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