moondaddy,
In addition to the other comments:
Does your byte array contain Char codes, such as ASCII, ANSI, or Unicode
characters? In which case you can use System.Text.Enc oding.GetBytes &
Encoding.GetStr ing to convert to & from a string (as Cor & Herfried
suggested).
Of if you simply want a comma delimited list of numbers from the Byte Array
I would create a couple of helper functions (As Peter suggested).
Something like:
Private Shared Function ArrayToString(B yVal bytes() As Byte, Optional
ByVal format As String = Nothing) As String
If bytes.Length = 0 Then Return String.Empty
Dim sb As New System.Text.Str ingBuilder(byte s.Length * 4)
For Each b As Byte In bytes
sb.Append(b.ToS tring(format))
sb.Append(","c)
Next
sb.Length -= 1
Return sb.ToString()
End Function
Private Shared Function StringToArray(B yVal s As String, Optional ByVal
style As System.Globaliz ation.NumberSty les = Nothing) As Byte()
If s.Length = 0 Then Return New Byte() {}
Dim values() As String = s.Split(","c)
Dim bytes(values.Le ngth - 1) As Byte
For index As Integer = 0 To values.Length - 1
bytes(index) = Byte.Parse(valu es(index), style)
Next
Return bytes
End Function
Public Shared Sub Main()
Dim mByte() As Byte = New Byte() {11, 22, 33, 44}
Dim myStr As String
'myStr = ArrayToString(m Byte, "x2")
myStr = ArrayToString(m Byte)
Debug.WriteLine (myStr)
mByte = Nothing
'mByte = StringToArray(m yStr,
Globalization.N umberStyles.All owHexSpecifier)
mByte = StringToArray(m yStr)
End Sub
Hope this helps
Jay
"moondaddy" <mo*******@nosp am.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
| I'm writing an app in vb.net 1.1 and need to convert a byte array into a
| string, and then from a string back to a byte array.
|
| for example
|
| Private mByte() as New Byte(4){11,22,3 3,44}
|
| Now how do I convert it to:
| dim myStr as string = "11,22,33,4 4"
|
| and then back to the byte array?
|
| Thanks.
|
|
|
| --
|
mo*******@nospa m.nospam
|
|