Posted: Tue Jul 19, 2005 6:53 am Post subject: converting messageid from byte to string
Novice
Joined: 03 Jun 2005 Posts: 19
Hello
I'm trying to convert message id from byte to string. Then from the string I would convert back to byte and put it in the correlation id to get the response message
Here are my first two functions to convert from byte to string and string to byte
Public Shared Function StrToByteArray(ByVal str As String) As Byte()
Dim encoding As New System.Text.ASCIIEncoding
Return encoding.GetBytes(str)
End Function 'StrToByteArray
Public Shared Function BytetoStr(ByVal byte_array As Byte()) As String
Dim str As String
Dim enc As New System.Text.ASCIIEncoding
str = enc.GetString(byte_array)
Return str
End Function
My second try with two new functions
Public Shared Function ConvertStringToByteArray(ByVal stringToConvert As String) As Byte()
Return (New UnicodeEncoding).GetBytes(stringToConvert)
End Function
Public Shared Function ConvertByteToString(ByVal byteToConvert() As Byte) As String
Return (New UnicodeEncoding).GetString(byteToConvert)
End Function
I also get a bunch of squares for the string that was converted from byte.
I am just wondering if you have any suggestions on how I can convert from byte to string and receive some normal standard characters for MQ.
Posted: Tue Jul 19, 2005 6:57 am Post subject: Re: converting messageid from byte to string
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
btdo wrote:
I am just wondering if you have any suggestions on how I can convert from byte to string
DON'T!
Search here for any of ten million posts that explain why you should not do this.
Also, you should go back and review the MQAX and .NET API, as there's already a simple way to get a printable version - for example the property MessageIdHex.
But you should not convert, and then convert back when setting the output property. Just copy the bytes as is. _________________ I am *not* the model of the modern major general.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum