CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Nov 2013

    VBNET function to convert charset encoding to windows-1256

    am looking for simple vb.net function to convert text to windows-1256.

    For example the below text :

    كلمة المركز
    when I try to convert it to proper Arabic language I used the online tool http://iosart.com/tools/charset-fixer then choosed Arabic(windows-1256).
    I used the below function with no use :

    Public Function ConvertUTF8StringEncoding(ByVal StringToConvert As String, Optional ByVal TargetCharSet As String = "windows-1256") As Byte()
    Dim ByteConvertedString() As Byte
    Dim ByteStringToConvert() As Byte
    Dim TargetEncoding As Encoding
    ' Convert the string to a Byte array
    ByteStringToConvert = Encoding.UTF8.GetBytes(StringToConvert.ToCharArray)
    ' Get the target encoding type
    TargetEncoding = Encoding.GetEncoding(TargetCharSet)
    ' Convert the byte array using the target encoding
    ByteConvertedString = Encoding.Convert(System.Text.Encoding.UTF8, TargetEncoding, ByteStringToConvert)
    Return ByteConvertedString
    End Function
    Private Function BinaryUTF8ToString(ByVal Binary() As Byte) As String
    Return System.Text.UnicodeEncoding.UTF8.GetString(Binary)
    End Function
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim stringConvertedString As String = BinaryUTF8ToString(ConvertUTF8StringEncoding("كلمة المركز "))
    lbresult.Text = stringConvertedString
    End Sub
    The result was : ???E C????? and it suppose to be : كلمة المركز
    Last edited by HanneSThEGreaT; November 18th, 2013 at 06:13 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.