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

string problem

P: n/a
On my form i have a message box called txtItemDesc that displays the french
phrase qualité Père Noël. Now then when i run this code on that text box:

Dim chrArr() As Char
chrArr = txtItemDesc.Text.ToCharArray
Dim pos As Integer
While pos < chrArr.Length
Dim c As Char
MsgBox(Asc(chrArr(pos)) & " " & chrArr(pos))
pos = pos + 1
End While

I get this as my message box reply:
113 q (which is right in the ascii char set)
117 u
97 a
108 l
105 i
116 t
233 é (this is wrong in the extend ascii char set it should be 130)

How do i get this message box to print out the write ascii char value?

Nov 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
john <jo**@discussions.microsoft.com> wrote:
On my form i have a message box called txtItemDesc that displays the french
phrase qualit? P?re No?l. Now then when i run this code on that text box:

Dim chrArr() As Char
chrArr = txtItemDesc.Text.ToCharArray
Dim pos As Integer
While pos < chrArr.Length
Dim c As Char
MsgBox(Asc(chrArr(pos)) & " " & chrArr(pos))
pos = pos + 1
End While

I get this as my message box reply:
113 q (which is right in the ascii char set)
117 u
97 a
108 l
105 i
116 t
233 ? (this is wrong in the extend ascii char set it should be 130)

How do i get this message box to print out the write ascii char value?


There's no single "extended ASCII" character set, and the plain ASCII
encoding only goes as far as 127.

You should use the *unicode* character you're interested in, and
preferrably avoid Asc which uses (IIRC) the default encoding for the
platform, which could be confusing things.

See http://www.pobox.com/~skeet/csharp/unicode.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2

P: n/a
The problem i have is that i'm sending this data to a case labeling printer
that requires ascii. Now it does use the extended ascii set i know there are
multiples of them but the most common one of them is used. Here is a page
that has the extend chars that i need: http://www.lookuptables.com/
so is there a way to get those extended char values from the input string?

"Jon Skeet [C# MVP]" wrote:
john <jo**@discussions.microsoft.com> wrote:
On my form i have a message box called txtItemDesc that displays the french
phrase qualit? P?re No?l. Now then when i run this code on that text box:

Dim chrArr() As Char
chrArr = txtItemDesc.Text.ToCharArray
Dim pos As Integer
While pos < chrArr.Length
Dim c As Char
MsgBox(Asc(chrArr(pos)) & " " & chrArr(pos))
pos = pos + 1
End While

I get this as my message box reply:
113 q (which is right in the ascii char set)
117 u
97 a
108 l
105 i
116 t
233 ? (this is wrong in the extend ascii char set it should be 130)

How do i get this message box to print out the write ascii char value?


There's no single "extended ASCII" character set, and the plain ASCII
encoding only goes as far as 127.

You should use the *unicode* character you're interested in, and
preferrably avoid Asc which uses (IIRC) the default encoding for the
platform, which could be confusing things.

See http://www.pobox.com/~skeet/csharp/unicode.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 22 '05 #3

P: n/a
john <jo**@discussions.microsoft.com> wrote:
The problem i have is that i'm sending this data to a case labeling printer
that requires ascii.
No, it requires more than just ASCII by the sounds of it - as I said
before, actual ASCII only goes up as far as 127.
Now it does use the extended ascii set i know there are
multiples of them but the most common one of them is used. Here is a page
that has the extend chars that i need: http://www.lookuptables.com/
so is there a way to get those extended char values from the input string?


That's far from the most common these days (despite what the web page
says) - it's an encoding from the DOS days. I *suspect* it's code page
437, which you can get with Encoding.GetEncoding(437). It's worth
trying, certainly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #4

P: n/a
thanks for the help Jon. You are right. it looks like the 437 char set is
the one I want. example of the set can be found at
http://www.georgehernandez.com/xComp...erSets/OEM.htm
I double check my label printers on my line i sent the ascii value of
char(130) and i recieved the results that i expected. now then i'm having a
problem with the conversion of the string still maybe you or someone can
point out where i'm going wrong. I'm still getting a code of 233 for char é
when it should be 130
'conversion code for my 437 encoding
' Create two different encodings.
Dim ibm437 As Encoding = Encoding.GetEncoding(437)
Dim [unicode] As Encoding = Encoding.Unicode

' Convert the string into a byte[].
Dim unicodeBytes As Byte() = [unicode].GetBytes(Me.TextBox1.Text)

' Perform the conversion from one encoding to the other.
Dim ibm437Bytes As Byte() = Encoding.Convert([unicode], ibm437,
unicodeBytes)

' Convert the new byte[] into a char[] and then into a string.
Dim imb437Chars(ibm437.GetCharCount(ibm437Bytes, 0,
ibm437Bytes.Length)) As Char
ibm437.GetChars(ibm437Bytes, 0, ibm437Bytes.Length, imb437Chars, 0)
Dim imb437String As New String(imb437Chars)

'checking my results from the conversion in a message box
Dim chrArr() As Char
chrArr = imb437String.ToCharArray

Dim pos As Integer
While pos < chrArr.Length
Dim c As Char
MsgBox(Asc(chrArr(pos)) & " " & chrArr(pos))
pos = pos + 1
End While

"Jon Skeet [C# MVP]" wrote:
john <jo**@discussions.microsoft.com> wrote:
The problem i have is that i'm sending this data to a case labeling printer
that requires ascii.


No, it requires more than just ASCII by the sounds of it - as I said
before, actual ASCII only goes up as far as 127.
Now it does use the extended ascii set i know there are
multiples of them but the most common one of them is used. Here is a page
that has the extend chars that i need: http://www.lookuptables.com/
so is there a way to get those extended char values from the input string?


That's far from the most common these days (despite what the web page
says) - it's an encoding from the DOS days. I *suspect* it's code page
437, which you can get with Encoding.GetEncoding(437). It's worth
trying, certainly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 22 '05 #5

P: n/a
it seems to me by doing this it is converting it back into a uncode string
because i'm putting the Encoded 437 chars back into a windows char array.

right?
"john" wrote:
thanks for the help Jon. You are right. it looks like the 437 char set is
the one I want. example of the set can be found at
http://www.georgehernandez.com/xComp...erSets/OEM.htm
I double check my label printers on my line i sent the ascii value of
char(130) and i recieved the results that i expected. now then i'm having a
problem with the conversion of the string still maybe you or someone can
point out where i'm going wrong. I'm still getting a code of 233 for char é
when it should be 130
'conversion code for my 437 encoding
' Create two different encodings.
Dim ibm437 As Encoding = Encoding.GetEncoding(437)
Dim [unicode] As Encoding = Encoding.Unicode

' Convert the string into a byte[].
Dim unicodeBytes As Byte() = [unicode].GetBytes(Me.TextBox1.Text)

' Perform the conversion from one encoding to the other.
Dim ibm437Bytes As Byte() = Encoding.Convert([unicode], ibm437,
unicodeBytes)

' Convert the new byte[] into a char[] and then into a string.
Dim imb437Chars(ibm437.GetCharCount(ibm437Bytes, 0,
ibm437Bytes.Length)) As Char
ibm437.GetChars(ibm437Bytes, 0, ibm437Bytes.Length, imb437Chars, 0)
Dim imb437String As New String(imb437Chars)

'checking my results from the conversion in a message box
Dim chrArr() As Char
chrArr = imb437String.ToCharArray

Dim pos As Integer
While pos < chrArr.Length
Dim c As Char
MsgBox(Asc(chrArr(pos)) & " " & chrArr(pos))
pos = pos + 1
End While

"Jon Skeet [C# MVP]" wrote:
john <jo**@discussions.microsoft.com> wrote:
The problem i have is that i'm sending this data to a case labeling printer
that requires ascii.


No, it requires more than just ASCII by the sounds of it - as I said
before, actual ASCII only goes up as far as 127.
Now it does use the extended ascii set i know there are
multiples of them but the most common one of them is used. Here is a page
that has the extend chars that i need: http://www.lookuptables.com/
so is there a way to get those extended char values from the input string?


That's far from the most common these days (despite what the web page
says) - it's an encoding from the DOS days. I *suspect* it's code page
437, which you can get with Encoding.GetEncoding(437). It's worth
trying, certainly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 22 '05 #6

P: n/a
nevermind thanks for the help i started to write my own converter for it.
it's working now.

"john" wrote:
it seems to me by doing this it is converting it back into a uncode string
because i'm putting the Encoded 437 chars back into a windows char array.

right?
"john" wrote:
thanks for the help Jon. You are right. it looks like the 437 char set is
the one I want. example of the set can be found at
http://www.georgehernandez.com/xComp...erSets/OEM.htm
I double check my label printers on my line i sent the ascii value of
char(130) and i recieved the results that i expected. now then i'm having a
problem with the conversion of the string still maybe you or someone can
point out where i'm going wrong. I'm still getting a code of 233 for char é
when it should be 130
'conversion code for my 437 encoding
' Create two different encodings.
Dim ibm437 As Encoding = Encoding.GetEncoding(437)
Dim [unicode] As Encoding = Encoding.Unicode

' Convert the string into a byte[].
Dim unicodeBytes As Byte() = [unicode].GetBytes(Me.TextBox1.Text)

' Perform the conversion from one encoding to the other.
Dim ibm437Bytes As Byte() = Encoding.Convert([unicode], ibm437,
unicodeBytes)

' Convert the new byte[] into a char[] and then into a string.
Dim imb437Chars(ibm437.GetCharCount(ibm437Bytes, 0,
ibm437Bytes.Length)) As Char
ibm437.GetChars(ibm437Bytes, 0, ibm437Bytes.Length, imb437Chars, 0)
Dim imb437String As New String(imb437Chars)

'checking my results from the conversion in a message box
Dim chrArr() As Char
chrArr = imb437String.ToCharArray

Dim pos As Integer
While pos < chrArr.Length
Dim c As Char
MsgBox(Asc(chrArr(pos)) & " " & chrArr(pos))
pos = pos + 1
End While

"Jon Skeet [C# MVP]" wrote:
john <jo**@discussions.microsoft.com> wrote:
> The problem i have is that i'm sending this data to a case labeling printer
> that requires ascii.

No, it requires more than just ASCII by the sounds of it - as I said
before, actual ASCII only goes up as far as 127.

> Now it does use the extended ascii set i know there are
> multiples of them but the most common one of them is used. Here is a page
> that has the extend chars that i need: http://www.lookuptables.com/
> so is there a way to get those extended char values from the input string?

That's far from the most common these days (despite what the web page
says) - it's an encoding from the DOS days. I *suspect* it's code page
437, which you can get with Encoding.GetEncoding(437). It's worth
trying, certainly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.