String to numeric?

  • Thread starter Thread starter Michael Turner
  • Start date Start date
M

Michael Turner

Hi Guys

Is there a way to brake up a text string and convert it to the relivant
ascii values?

Thanks

Mike.
 
Hi Michael,

You mean something as (roughly typed here)
\\\
dim x(mystring.length) as integer
for i as integer = 0 to mystring.length - 1
x(i) = AscW(mystring.substring(i,1))
next
///

This is not to numeric by the way and it is a kind of ASCII values, while it
does more than 7 bits.

I hope this helps?

Cor
 
Hi,

One option is to use the ASCIIEncoding.GetBytes() method - the overload that
takes a string as the parameter.

Hi Guys

Is there a way to brake up a text string and convert it to the relivant
ascii values?

Thanks

Mike.
 
* "Michael Turner said:
Is there a way to brake up a text string and convert it to the relivant
ascii values?

\\\
Dim abyt() As Byte = System.Text.Encoding.ASCII.GetBytes("Hello World!")
Dim b As Byte
For Each b In abyt
MsgBox(b.ToString())
Next b
///
 
Michael,
As the others have suggested.

ASCII is 7 bit values (0 to 127), do you perhaps want ANSI (8 bit values (0
to 255))?

You can use Asc to get the ANSI value of a character, of the current Windows
code page.

You can use AscW to get the Unicode value of a character. Remember that
characters & strings in .NET are kept in Unicode.

You can use System.Text.Encoding.ASCII.GetBytes to get the entire string as
an array of ASCII bytes.

You can use System.Text.Encoding.Default.GetBytes to get the entire string
as an array of ANSI bytes of the current Windows code page.

Note Encoding.ASCII & Encoding.Default are shared properties that return a
System.Text.Encoding object, there are other shared properties for other
encodings.

For information on ASCII, ANSI, Unicode and how Encoding works see:

http://www.yoda.arachsys.com/csharp/unicode.html

Hope this helps
Jay
 
Michael,
You can use Chr to undo Asc.

You can use ChrW to undo AscW.

You can use Encoding.GetString to undo Encoding.GetBytes, for example
System.Text.Encoding.ASCII.GetString.

Hope this helps
Jay
 
Hi Michael

I know no better way that this for it
\\\
Dim sb As New System.Text.StringBuilder
For i As Integer = 0 To x.Length - 1
sb.Append(ChrW(x(i)))
Next
Dim thestring As String = sb.ToString
////

However maybe it can direct (but you see now nice the ChrW) and the
stringbuilder.

Cor
 
Back
Top