[RESOLVED] Converting a char/string to an int?
Is there any way to convert a char or string to an int?
Such as if I have the letter "A" I could get the ascii value of this character I think it's 65 I think so I could do something like
Dim strTest as string
strTest = "A"
Dim intTest as Integer
intTest = strTest
Though I know I have to convert strTest somehow I just don't know how. I can then work with the int value.
Thanks for all you help.
Mythos
Re: Converting a char/string to an int?
If youre only planning to store one character then dont use a string, use a char. Then use Asc() to get the Ascii value.
VB.Net Code:
Dim c As Char = "A"c
Dim charAscii As Integer = Asc(c)
Re: Converting a char/string to an int?
There's a way to convert a Char to an Integer: Convert.ToInt32. The converse is Convert.ToChar. If you have a String to begin with then you can get individual characters from its Chars collection. That said, if you want a variable to store an individual character then it should be type Char to begin with.
Re: Converting a char/string to an int?
Try
Dim i as int16 = Convert.ToInt16(Asc("A"))
Re: Converting a char/string to an int?
Thank you so much this works great.
Mythos