Results 1 to 5 of 5

Thread: [RESOLVED] Converting a char/string to an int?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    63

    Resolved [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.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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:
    1. Dim c As Char = "A"c
    2.         Dim charAscii As Integer = Asc(c)
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Addicted Member
    Join Date
    Feb 2008
    Location
    California
    Posts
    151

    Re: Converting a char/string to an int?

    Try

    Dim i as int16 = Convert.ToInt16(Asc("A"))

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    63

    Smile 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
  •  



Click Here to Expand Forum to Full Width