VB To C# ( _value = Asc(Mid(LStr, IValue, 1)))
-
Hello, I wrote this a while ago and I need some help converting it to C#. "( _value = Asc(Mid(LStr, IValue, 1)))"
-
Hello, I wrote this a while ago and I need some help converting it to C#. "( _value = Asc(Mid(LStr, IValue, 1)))"
Mid
is the equivalent ofSubstring
. Rather than passing in LStr, you useSubstring
on that, so you'd haveLStr.Substring
. LValue is the start position and 1 is the length that you pass in to theSubstring
method.Asc
just returns the ASCII code, so all you need to do is convert the single character from your Substring to anint
.*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
Mid
is the equivalent ofSubstring
. Rather than passing in LStr, you useSubstring
on that, so you'd haveLStr.Substring
. LValue is the start position and 1 is the length that you pass in to theSubstring
method.Asc
just returns the ASCII code, so all you need to do is convert the single character from your Substring to anint
.*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
Thanks I did the following. I added the VisualBasic Reference and used Strings.Asc. Then for the Mid I use:
public static string Mid(string param, int startIndex, int length)
{
string result = param.Substring(startIndex, length);
return result;
} -
Thanks I did the following. I added the VisualBasic Reference and used Strings.Asc. Then for the Mid I use:
public static string Mid(string param, int startIndex, int length)
{
string result = param.Substring(startIndex, length);
return result;
}blackchaosv2 wrote:
I added the VisualBasic Reference and used Strings.Asc
There was no reason to do this. It is easily accomplished without adding a heavy DLL reference. There are many, many ways to get the char out - one way is to use
char.Parse(Mid(LStr, startIndex, 1))
and then cast this to anint
.*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
Hello, I wrote this a while ago and I need some help converting it to C#. "( _value = Asc(Mid(LStr, IValue, 1)))"
-
Hello, I wrote this a while ago and I need some help converting it to C#. "( _value = Asc(Mid(LStr, IValue, 1)))"
Remember, legacy VB string functions are 1-based, not 0-based, so the equivalent is:
_value = Convert.ToInt32(LStr[IValue - 1]));
David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com Instant C# - VB to C# Converter Instant VB - C# to VB Converter
-
Remember, legacy VB string functions are 1-based, not 0-based, so the equivalent is:
_value = Convert.ToInt32(LStr[IValue - 1]));
David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com Instant C# - VB to C# Converter Instant VB - C# to VB Converter
Unless he's got the position using one of the inbuilt .NET routines.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier