H
Hugh Janus
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(ByVal 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.StringBuilder(bytes.Length * 4)
For Each b As Byte In bytes
sb.Append(b.ToString(format))
sb.Append(","c)
Next
sb.Length -= 1
Return sb.ToString()
End Function
Private Function StringToArray(ByVal s As String, Optional ByVal
style As System.Globalization.NumberStyles = Nothing) As Byte()
If s.Length = 0 Then Return New Byte() {}
Dim values() As String = s.Split(","c)
Dim bytes(values.Length - 1) As Byte
For index As Integer = 0 To values.Length - 1
bytes(index) = Byte.Parse(EncStr, style)
bytes(index) = Byte.Parse(values(index), style)
Next
Return bytes
End Function
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(ByVal 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.StringBuilder(bytes.Length * 4)
For Each b As Byte In bytes
sb.Append(b.ToString(format))
sb.Append(","c)
Next
sb.Length -= 1
Return sb.ToString()
End Function
Private Function StringToArray(ByVal s As String, Optional ByVal
style As System.Globalization.NumberStyles = Nothing) As Byte()
If s.Length = 0 Then Return New Byte() {}
Dim values() As String = s.Split(","c)
Dim bytes(values.Length - 1) As Byte
For index As Integer = 0 To values.Length - 1
bytes(index) = Byte.Parse(EncStr, style)
bytes(index) = Byte.Parse(values(index), style)
Next
Return bytes
End Function