Hi all,
I am using the below functions in order to convert strings to bytes and
vice versa. I totally ans shamefully stole these functions from this
group btw! Anyway, they work great but as sooooo slow. Anyone know
how I can speed this functions up? I basically need to convert a byte
to string, perform a function on each 'section' of the string, then
reconvert it to a byte. The slow part is the conversion to and from
byte, not the part I am doing in between after conversion.
TIA
Private 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 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(EncS tr, style)
bytes(index) = Byte.Parse(valu es(index), style)
Next
Return bytes
End Function