I need to write some information to a text File using ascii encoding and code page 1256 windows-arabic bcz my string conatins both arabic and english chars I try to use Encoding.Ascii to do the conversion but the code page used is 20127 so the arabic chars is saved to file as ????????? and I coludn't change the code page to my desired one
how I can save the information to the text file using ascii encoding with the correct code page
Wednesday, January 06, 2010 12:39 PM
- Changed type Samer Selo Wednesday, January 06, 2010 12:41 PM it's question
You can do something like this:
''' Code posted by Xun Ye [http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/e17f99a9-f4fa-49a6-82da-0c73d930224d/] Class Program Private Shared Sub Main(ByVal args As String()) ConvertFile(28596, 1256, "F:\sourceFile.txt", "F:\destFile.txt") End Sub '=28596 '=1256 Private Shared Sub ConvertFile(ByVal fromEncode As Integer, ByVal toEncode As Integer, ByVal sourceFilePath As String, ByVal DestFilePath As String) Dim fs As New FileStream(sourceFilePath, FileMode.Open) Dim br As New BinaryReader(fs) Dim orignalEncode As Byte() = br.ReadBytes(CInt(fs.Length)) br.Close() fs.Close() Dim unEncodedText As String = Encoding.GetEncoding(fromEncode).GetString(orignalEncode) fs = New FileStream(DestFilePath, FileMode.Create) Dim bw As New BinaryWriter(fs) Dim encodedBuffer As Byte() = Encoding.GetEncoding(fromEncode).GetBytes(unEncodedText) bw.Write(encodedBuffer, 0, encodedBuffer.Length) bw.Flush() bw.Close() End Sub End ClassI've changed it, sorry, this is definetly one of those days which I should be more aware, I'm sorry.
Hope it helps.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
BlogWednesday, January 06, 2010 1:01 PM
The Code in C and it's wrong the toEncode is not used inside the procedure
I want to save a string variable wich have unicode format by default to ascii text file using code page 1256 the process of saving the string is used to create the file
Wednesday, January 06, 2010 6:05 PM
- Edited by Samer Selo Wednesday, January 06, 2010 6:12 PM