Encoding.GetString() doesn't return proper length

.net , vb.net , asp.net Pune, India
  • 8 years ago

    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

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Walking on water and developing software from a specification are easy if both are frozen.” - Edward V Berard