Endoding a THAI string into unicode

visualliser

New member
Joined
Apr 27, 2006
Messages
1
Programming Experience
5-10
Original String:
Ki KiE:สวัสดีค่ะ โปรแกรม โอเอ็มเอส โดย บริษัท เอ็มเอสแอล ซอฟต์แวร์

Problems Facing:

1. The missing '00' in the begining and trailing part of the generated string
2. The white spaces within the original string (in THAI) show up junk characters instead of SPACE.

Please check this by pasting the source code attached and help me out in generating Correct output.

thanks in advance.

Correct Output which i am expecting to generate

004B00690020004B00690045003A00200E2A0E270E310E2A0E140E350E040E480E3000200E420E1B0E230E410E010E230E2100200E420E2D0E400E2D0E470E2100200E400E2D0E2A00200E420E140E2200200E1A0E230E340E290E310E1700200E400E2D0E470E2100200E400E2D0E2A00200E410E2D0E2500200E0B0E2D0E1F0E150E4C0E410E270E230E4C

Present Output which is wrong

4B00690014004B00690045003A0014002A0E270E310E2A0E140E350E040E480E300E1400420E1B0E230E410E010E230E210E1400420E2D0E400E2D0E470E210E400E2D0E2A0E1400420E140E220E14001A0E230E340E290E310E170E1400400E2D0E470E210E400E2D0E2A0E410E2D0E250E14000B0E2D0E1F0E150E4C0E410E270E230E4C0E

Code responsible for conversion:

'-------FUNCTION CALLS -----------

Dim bytes() As Byte = ConvertStringToByteArray1(msg)
Dim str As String = bytetohexa(bytes)

'------ FUNCTION DEFINITIONS ---------


Public Shared Function ConvertStringToByteArray1(ByVal stringToConvert As String) As Byte()

Return (New System.Text.UnicodeEncoding).GetBytes(stringToConvert)

End Function


Private Function bytetohexa(ByVal bytes() As Byte) As String
Try

Dim sHex As New System.Text.StringBuilder(2 * bytes.Length)
Dim i As Integer

For i = 0 To bytes.Length - 1 Step 1
sHex.AppendFormat("{0:X2}", bytes(i))
Next

Return sHex.ToString().Replace(" ", String.Empty)

Catch ex As Exception
Return (vbNull)
End Try

End Function



One who is in search of knowledge.. should give up pleasure . visualliser -2006 A.D.
 
Back
Top