PC Review


Reply
Thread Tools Rate Thread

Byte arrays to string WITHOUT encoding/decoding

 
 
Jeff Stewart
Guest
Posts: n/a
 
      27th Nov 2004
I wrote the following function to accomodate a legacy driver function
that only accepted VB6-style strings. The driver expects a string
that represents an array of binary data to be sent over USB.

Private Function byteArrayToString(ByVal byteArray() As Byte) As
String
Dim returnString As String = New String("")
Dim i As Integer
For i = 0 To byteArray.Length - 1
returnString += Chr(byteArray(i))
Next
Return returnString
End Function

I wrote this function because all of the functions I found in
System.Text.Encoding insisted on interpreting my byte array of binary
data as UTF8 or ASCII or Unicode or whatever, effectively returning a
string that differed from the byte array on a character-by-character
basis. Most often, bytes like 0xE6 would be converted to 0x06.

Isn't there a .NET function that will do what I did?

--
Jeff S.
 
Reply With Quote
 
 
 
 
Hayato Iriumi
Guest
Posts: n/a
 
      27th Nov 2004
Hello Jeff,

System.Text.Encoding.ASCII(or Default maybe?).GetString(blah, blah);

Hope this helps.


> I wrote the following function to accomodate a legacy driver function
> that only accepted VB6-style strings. The driver expects a string
> that represents an array of binary data to be sent over USB.
>
> Private Function byteArrayToString(ByVal byteArray() As Byte) As
> String
> Dim returnString As String = New String("")
> Dim i As Integer
> For i = 0 To byteArray.Length - 1
> returnString += Chr(byteArray(i))
> Next
> Return returnString
> End Function
> I wrote this function because all of the functions I found in
> System.Text.Encoding insisted on interpreting my byte array of binary
> data as UTF8 or ASCII or Unicode or whatever, effectively returning a
> string that differed from the byte array on a character-by-character
> basis. Most often, bytes like 0xE6 would be converted to 0x06.
>
> Isn't there a .NET function that will do what I did?
>
> --
> Jeff S.



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      27th Nov 2004
Jeff,

I do not know a VB6 style string, maybe you mean a MS-Dos code page format
byte array.

You can than try this one
\\\
Dim Str As New StreamReader(FilePath)
Dim arrInput As Byte() = _
System.Text.Encoding.GetEncoding(437).GetBytes(Str.ReadToEnd)
Str.Close()
///

This assumes that the codepage 437 is active in your country setting.

However a string in dotNet is forever a two byte unicode string.

I hope this helps?

Cor

"Jeff Stewart" <(E-Mail Removed)>

>I wrote the following function to accomodate a legacy driver function
> that only accepted VB6-style strings. The driver expects a string
> that represents an array of binary data to be sent over USB.
>
> Private Function byteArrayToString(ByVal byteArray() As Byte) As
> String
> Dim returnString As String = New String("")
> Dim i As Integer
> For i = 0 To byteArray.Length - 1
> returnString += Chr(byteArray(i))
> Next
> Return returnString
> End Function
>
> I wrote this function because all of the functions I found in
> System.Text.Encoding insisted on interpreting my byte array of binary
> data as UTF8 or ASCII or Unicode or whatever, effectively returning a
> string that differed from the byte array on a character-by-character
> basis. Most often, bytes like 0xE6 would be converted to 0x06.
>
> Isn't there a .NET function that will do what I did?
>
> --
> Jeff S.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Encoding byte array to string John Microsoft Access 0 28th Jul 2008 01:23 PM
Universal String (4 Byte Canonical Encoding) and UTF-32 Jeffrey Walton Microsoft C# .NET 2 22nd Nov 2007 03:19 AM
query string encoding/decoding =?Utf-8?B?TWFyaw==?= Microsoft ASP .NET 9 5th Apr 2004 05:02 PM
ASN.1 Encoding/Decoding in .NET? Nikola Kasev Microsoft Dot NET Framework 0 21st Feb 2004 01:28 PM
Reliable conversion from byte() to string WITHOUT use of System.Text.Encoding I.Charitopoulos Microsoft VB .NET 4 29th Aug 2003 03:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:46 PM.