
Problem with ASCIIEncoding.GetString
Quote:
>I'm having a problem converting a byte array to a string.
>In the VS.NET de{*filter*}, the string that's converted looks
>like "MyString instead of "MyString". The ending
>quotation mark isn't there, and it's causing problems when
>I'm using a Mid function to capture a few characters from
>the end of the string (i.e. "MyString apparently isn't the
>same as "MyString"). Below is my code.
[code snipped]
Quote:
>Any help or suggestions are appreciated. Thanks!
I can reproduce the problem at my side.
However, I notice if you append a char to the byte, the " will be
tailed.
A workaround:
Dim r_bytes(26) As Byte
Dim i As Integer
Dim s As String
For i = 0 To 25
r_bytes(i) = Asc("A") + i
Next
r_bytes(26) = Asc(" ") ' Tailing with a char
s = System.Text.Encoding.ASCII.GetString(r_bytes, 0,
r_bytes.Length - 1) ' length - 1
Debug.Write(s)
HTH.
--
Peter Wu
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no
rights.