|
-
Feb 6th, 2008, 06:35 PM
#1
Thread Starter
Member
[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
Last edited by Mythos44; Feb 6th, 2008 at 07:40 PM.
Reason: My question has been resolved.
-
Feb 6th, 2008, 06:40 PM
#2
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)
-
Feb 6th, 2008, 06:40 PM
#3
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.
-
Feb 6th, 2008, 06:46 PM
#4
Addicted Member
Re: Converting a char/string to an int?
Try
Dim i as int16 = Convert.ToInt16(Asc("A"))
-
Feb 6th, 2008, 07:39 PM
#5
Thread Starter
Member
Re: Converting a char/string to an int?
Thank you so much this works great.
Mythos
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|