M
moondaddy
I need to convert a byte array to a string and pass it as a parameter in a
URL and then convert it back to the original byte array. However, its
getting scrambled in the conversion. In short, here's the code:
======================================
Dim textConverter As New ASCIIEncoding
Dim sParam As String = "This is my cool param"
Dim bytParam() As Byte
'load the byte array here...
'convert byte() to string
sParam = textConverter.GetString(bytParam)
'convert string to byte()
bytParam = textConverter.GetBytes(sParam)
=====================================
bytParam is not the same as it was before it was converted to a string.
How can I do this and preserve the byte() to exactly what it was when I
started?
Here's bytParams before converting to a string: (copied from the watch
window)
bytParam {Length=32} Byte()
0 27 Byte
-1 163 Byte
-2 198 Byte
-3 42 Byte
-4 46 Byte
-5 191 Byte
-6 236 Byte
-7 250 Byte
-8 163 Byte
-9 211 Byte
-10 222 Byte
-11 98 Byte
-12 31 Byte
-13 86 Byte
-14 223 Byte
-15 64 Byte
-16 164 Byte
-17 197 Byte
-18 1 Byte
-19 180 Byte
-20 102 Byte
-21 129 Byte
-22 246 Byte
-23 148 Byte
-24 204 Byte
-25 35 Byte
-26 8 Byte
-27 15 Byte
-28 36 Byte
-29 31 Byte
-30 1 Byte
-31 253 Byte
and here it is after restoring it back from a string:
bytParam {Length=32} Byte()
0 27 Byte
-1 35 Byte
-2 70 Byte
-3 42 Byte
-4 46 Byte
-5 63 Byte
-6 108 Byte
-7 122 Byte
-8 35 Byte
-9 83 Byte
-10 94 Byte
-11 98 Byte
-12 31 Byte
-13 86 Byte
-14 95 Byte
-15 64 Byte
-16 36 Byte
-17 69 Byte
-18 1 Byte
-19 52 Byte
-20 102 Byte
-21 1 Byte
-22 118 Byte
-23 20 Byte
-24 76 Byte
-25 35 Byte
-26 8 Byte
-27 15 Byte
-28 36 Byte
-29 31 Byte
-30 1 Byte
-31 125 Byte
Thanks!
URL and then convert it back to the original byte array. However, its
getting scrambled in the conversion. In short, here's the code:
======================================
Dim textConverter As New ASCIIEncoding
Dim sParam As String = "This is my cool param"
Dim bytParam() As Byte
'load the byte array here...
'convert byte() to string
sParam = textConverter.GetString(bytParam)
'convert string to byte()
bytParam = textConverter.GetBytes(sParam)
=====================================
bytParam is not the same as it was before it was converted to a string.
How can I do this and preserve the byte() to exactly what it was when I
started?
Here's bytParams before converting to a string: (copied from the watch
window)
bytParam {Length=32} Byte()
0 27 Byte
-1 163 Byte
-2 198 Byte
-3 42 Byte
-4 46 Byte
-5 191 Byte
-6 236 Byte
-7 250 Byte
-8 163 Byte
-9 211 Byte
-10 222 Byte
-11 98 Byte
-12 31 Byte
-13 86 Byte
-14 223 Byte
-15 64 Byte
-16 164 Byte
-17 197 Byte
-18 1 Byte
-19 180 Byte
-20 102 Byte
-21 129 Byte
-22 246 Byte
-23 148 Byte
-24 204 Byte
-25 35 Byte
-26 8 Byte
-27 15 Byte
-28 36 Byte
-29 31 Byte
-30 1 Byte
-31 253 Byte
and here it is after restoring it back from a string:
bytParam {Length=32} Byte()
0 27 Byte
-1 35 Byte
-2 70 Byte
-3 42 Byte
-4 46 Byte
-5 63 Byte
-6 108 Byte
-7 122 Byte
-8 35 Byte
-9 83 Byte
-10 94 Byte
-11 98 Byte
-12 31 Byte
-13 86 Byte
-14 95 Byte
-15 64 Byte
-16 36 Byte
-17 69 Byte
-18 1 Byte
-19 52 Byte
-20 102 Byte
-21 1 Byte
-22 118 Byte
-23 20 Byte
-24 76 Byte
-25 35 Byte
-26 8 Byte
-27 15 Byte
-28 36 Byte
-29 31 Byte
-30 1 Byte
-31 125 Byte
Thanks!