Question Encoding.GetString() doesn't return proper length

dmedsing2004

New member
Joined
Jun 28, 2010
Messages
2
Programming Experience
3-5
In advance thanks everybody. My issue is, My system has Japanese regional settings. I have used this as default encoding in my code. But Encoding.GetString() method doesn't return proper length because of DBCS. Can anybody has any solution over this. My code snippet is as below,

Imports System.Text

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim buffer(7) As Byte
Dim strRetEncryptKey As String = Nothing
Dim objDefaultEncoding As Encoding = Encoding.Default

Try
buffer(0) = 73
buffer(1) = 4
buffer(2) = 82
buffer(3) = 141
buffer(4) = 224
buffer(5) = 144
buffer(6) = 192
buffer(7) = 195

strRetEncryptKey = objDefaultEncoding.GetString(buffer)

MessageBox.Show("strRetEncryptKey = " & strRetEncryptKey & vbNewLine & " Length = " & strRetEncryptKey.Length)
Catch ex As Exception
MessageBox.Show(ex.Message)

End Try
End Sub
End Class
 
Are you sure you're using the right encoding? What code page and name does it have? A quick test here listed eight Japanese encodings, some of which are single byte, and some double byte (mixed) that returned six chars from those eight bytes. These are the codepages and encoding names that were presented:
932, shift_jis
10001, x-mac-japanese
20290, IBM290
20932, EUC-JP
50220, iso-2022-jp
50221, csISO2022JP
50222, iso-2022-jp
51932, euc-jp
 
Yes. I am using right encoding. My coding requirement is that only. I have to store array of bytes in the string as per system's current encoding. My system has selected all the code pages mentioned by you except only code page - 51932, euc-up.

Thanks
 
Back
Top