-
November 14th, 2013, 02:35 AM
#1
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 :
Code:
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 07:13 AM.
-
November 18th, 2013, 07:10 AM
#2
Re: VBNET function to convert charset encoding to windows-1256
I think you are over-complicating things.
This is all you need :
Code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strInput As String = "ßáãÉ ÇáãÑßÒ"
Dim btCharBytes As Byte() = Encoding.Default.GetBytes(strInput)
Dim strOutput As New String(Encoding.GetEncoding(1256).GetChars(btCharBytes))
lbResult.Text = strOutput
End Sub
Oh, and please remember to use CODE tags when posting code. It is explained here :
http://forums.codeguru.com/showthrea...for-more-info)
Last edited by HanneSThEGreaT; November 18th, 2013 at 07:12 AM.
-
November 18th, 2013, 07:32 AM
#3
Re: VBNET function to convert charset encoding to windows-1256
I forgot one little small detail, that you might also have set already.
Also remember to set your RightToLeft Property for the TextBox or Label to True
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|