By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

String to numeric?

P: n/a
Hi Guys

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

Thanks

Mike.

Nov 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
guy
Asc,AscW

hth

guy

"Michael Turner" wrote:
Hi Guys

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

Thanks

Mike.

Nov 20 '05 #2

P: n/a
Hi,

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

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:uX**************@tk2msftngp13.phx.gbl...
Hi Guys

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

Thanks

Mike.


Nov 20 '05 #3

P: n/a
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
Is there a way to brake up a text string and convert it to the relivant
ascii values?

Thanks

Mike.

Nov 20 '05 #4

P: n/a
* "Michael Turner" <fi*****@m-turner.co.uk> scripsit:
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
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #5

P: n/a
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 Turner" <fi*****@m-turner.co.uk> wrote in message
news:uX**************@tk2msftngp13.phx.gbl...
Hi Guys

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

Thanks

Mike.

Nov 20 '05 #6

P: n/a
Hi Cor

Thats great is there a way now of converting this back to text?

Mike.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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
Is there a way to brake up a text string and convert it to the relivant
ascii values?

Thanks

Mike.



Nov 20 '05 #7

P: n/a
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
"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:uD*************@TK2MSFTNGP12.phx.gbl...
Hi Cor

Thats great is there a way now of converting this back to text?

Mike.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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
Is there a way to brake up a text string and convert it to the relivant ascii values?

Thanks

Mike.



Nov 20 '05 #8

P: n/a
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
Hi Cor

Thats great is there a way now of converting this back to text?

Mike.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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
Is there a way to brake up a text string and convert it to the relivant ascii values?

Thanks

Mike.



Nov 20 '05 #9

P: n/a
Ok worked it out chr(asciivalue)
Thanks,

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:uD*************@TK2MSFTNGP12.phx.gbl...
Hi Cor

Thats great is there a way now of converting this back to text?

Mike.
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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
Is there a way to brake up a text string and convert it to the relivant ascii values?

Thanks

Mike.




Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.