Hi all, Couldnt find any information on this the other day when I was looking for it so I thought Id post how I done it.
VB Code:
'Write a byte array (in Unicode Big Endian) from a string Public Function WriteUnicodeBigEndian(Text As String) As Byte() Dim i As Integer, TempArray() As Byte ReDim TempArray(0 To Len(Text) * 2) For i = 0 To (Len(Text) * 2) If Len(Text) = 0 Then Exit For If i Mod 2 Then TempArray(i) = AscW(Text) Text = Right(Text, Len(Text) - 1) Else TempArray(i) = 0 End If Next i WriteUnicodeBigEndian = TempArray End Function 'Write a byte array (in Unicode Little Endian) from a string Public Function WriteUnicodeLittleEndian(Text As String) As Byte() Dim i As Integer, TempArray() As Byte ReDim TempArray(0 To Len(Text) * 2) For i = 0 To (Len(Text) * 2) If Len(Text) = 0 Then List2.AddItem 0 Exit For End If If i Mod 2 Then TempArray(i) = 0 Else TempArray(i) = AscW(Text) Text = Right(Text, Len(Text) - 1) End If Next i WriteUnicodeLittleEndian = TempArray End Function
There ya go, Them two functions converts the string passed to the function into an array in the format of Unicode Little Endian or Unicode Big Endian.
Enjoy.


Reply With Quote