Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding  
Author Message
Cecelia





PostPosted: Thu Aug 28 16:00:58 CDT 2003 Top

Visual Basic [VB] >> Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding The reason I want to do so, is that I am sending to DOS and I am pretty
certain that it will not work.
Everything I've tried so far hasnt.

In my test environment (Windows to Windows) this works perfectly, but not
when sending to DOS:

Private Function bytearray2string(ByVal input As Byte()) As String

Dim output As String

output = System.Text.Encoding.Default.GetString(input)

Return output

End Function



Private Function string2bytearray(ByVal input As String) As Byte()

Dim output() As Byte

output = System.Text.Encoding.Default.GetBytes(input)

Return output

End Function



I have also tried this, to no avail in Windows:

Private Function bytearray2string2(ByVal input As Byte()) As String

Dim output As String = ""

Dim i As Integer = 0

'Dim vchar As Char

While i < input.Length

output = output & CChar(Chr(input.GetValue(i)))

i = i + 1

End While

Return (output)

End Function



Private Function string2bytearray2(ByVal input As String) As Byte()

Dim output(input.Length - 1) As Byte

Dim i As Integer = 0

For i = 0 To UBound(output)

output(i) = CByte(Asc(input.Chars(i)))

Next

Return (output)

End Function

The desired functions need to use no encoding and be able to work with
simple bytes. The values I'll be receiving wont be higher anyway.

I'd appreciate any feedback whatsoever.

regards,
J

Visual Studio20  
 
 
Tom





PostPosted: Thu Aug 28 16:00:58 CDT 2003 Top

Visual Basic [VB] >> Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding Why not use ASCII encoding, instead of 'Default'

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit


"I.Charitopoulos" <EMail@HideDomain.com> wrote in message
news:#EMail@HideDomain.com...
> The reason I want to do so, is that I am sending to DOS and I am pretty
> certain that it will not work.
> Everything I've tried so far hasnt.
>
> In my test environment (Windows to Windows) this works perfectly, but not
> when sending to DOS:
>
> Private Function bytearray2string(ByVal input As Byte()) As String
>
> Dim output As String
>
> output = System.Text.Encoding.Default.GetString(input)
>
> Return output
>
> End Function
>
>
>
> Private Function string2bytearray(ByVal input As String) As Byte()
>
> Dim output() As Byte
>
> output = System.Text.Encoding.Default.GetBytes(input)
>
> Return output
>
> End Function
>
>
>
> I have also tried this, to no avail in Windows:
>
> Private Function bytearray2string2(ByVal input As Byte()) As String
>
> Dim output As String = ""
>
> Dim i As Integer = 0
>
> 'Dim vchar As Char
>
> While i < input.Length
>
> output = output & CChar(Chr(input.GetValue(i)))
>
> i = i + 1
>
> End While
>
> Return (output)
>
> End Function
>
>
>
> Private Function string2bytearray2(ByVal input As String) As Byte()
>
> Dim output(input.Length - 1) As Byte
>
> Dim i As Integer = 0
>
> For i = 0 To UBound(output)
>
> output(i) = CByte(Asc(input.Chars(i)))
>
> Next
>
> Return (output)
>
> End Function
>
> The desired functions need to use no encoding and be able to work with
> simple bytes. The values I'll be receiving wont be higher anyway.
>
> I'd appreciate any feedback whatsoever.
>
> regards,
> J
>
>
>
>
>


 
 
I





PostPosted: Fri Aug 29 01:37:49 CDT 2003 Top

Visual Basic [VB] >> Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding ASCII Encoding uses 7 bits out of the byte, so I'd be losing 1 bit out of
every byte of data that comes in.

I want to use the extended ASCII that uses all 8 bits, for values of 0 to
255.


"Tom Spink" <EMail@HideDomain.com> wrote in message
news:#EMail@HideDomain.com...
> Why not use ASCII encoding, instead of 'Default'
>
> --
> HTH,
> -- Tom Spink, Über Geek
>
> Please respond to the newsgroup,
> so all can benefit
>



 
 
Armin





PostPosted: Fri Aug 29 04:12:11 CDT 2003 Top

Visual Basic [VB] >> Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding "I.Charitopoulos" <EMail@HideDomain.com> schrieb
> The reason I want to do so, is that I am sending to DOS and I am
> pretty certain that it will not work.
> Everything I've tried so far hasnt.
>
> In my test environment (Windows to Windows) this works perfectly, but
> not when sending to DOS:
> [...]

Maybe codepage 850 is what you're looking for.

System.Text.Encoding.GetEncoding(850)

Use it to convert from/to byte arrays. There are other codepages

See also:
http://www.microsoft.com/globaldev/reference/cphome.mspx

To find the right encoding, open a DOS window and enter
mode con cp<enter>

Should return the encoding you need (but I'm not sure)

--
Armin

 
 
I





PostPosted: Fri Aug 29 09:55:11 CDT 2003 Top

Visual Basic [VB] >> Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding Thanx a lot for the tip. Will try that.

Seems like a reliable way of getting the encoding.

> Maybe codepage 850 is what you're looking for.
>
> System.Text.Encoding.GetEncoding(850)
>
> Use it to convert from/to byte arrays. There are other codepages
>
> See also:
> http://www.microsoft.com/globaldev/reference/cphome.mspx
>
> To find the right encoding, open a DOS window and enter
> mode con cp<enter>
>
> Should return the encoding you need (but I'm not sure)
>
> --
> Armin
>