VB.NET equivelent of chr$() and asc() ?

  • Thread starter Thread starter JustAProg
  • Start date Start date
J

JustAProg

Guest
Like the various uses of 'myString.substring' are used in vb.net instead of the old vb6 left, right and mid. Can someone tell me the vb.net version of, for example: chr$(34) and asc("Z"), thanks.

I don't want to use the above, or bring in the vb namespace, I'd like to find the proper vb.net way of doing them.

Thanks
 
Not sure if this is really any faster, but you can use the native
System.Convert class.
Visual Basic:
System.Windows.Forms.MessageBox.Show(System.Convert.ToChar(34)) 'Chr$(34)
System.Windows.Forms.MessageBox.Show(System.Convert.ToByte("Z"c)) 'Asc("Z")
 
Thank you. That's exactly what I was after, cheers.

By the way, what's the 'little c' for, I thought it was a typo to start with then realised it's needed, seems rather out of place if ya know what I mean.

>> ("Z"c) <<
 
The little c represents that the value in quote marks is a Char,
not a String, so you can tell the difference when debugging. The
ToChar method, as the name implies, returns a Char, not a String
like Chr$() does.
 
Good point Bucky. I should have pointed that out. You would
have to do one more conversion to get the Char converted to a
string. It has to be that way, because the ToString method would
just change 34 to "34".
 
Back
Top