aj l

aj l

  • NA
  • 1
  • 0

C# Code Converter

May 9 2006 2:39 AM
Still working on the same problem…
 
I need to open encoded files (DOS Hebrew).
Follow the link and download the file "Unrecognized files examples" to see examples:
 
http://rapidshare.de/files/19995657/Unrecognized_files_examples.rar.html
 
I succeeded with Excel following these steps:
 
1.- From Excel I open the file,(Excel does not recognize the file and ask me for an encoding format, I choose codepage 862 (Hebrew DOS), and save the file as (.txt).
 
2.- From Excel I open the (.txt) file and this time choosing codepage 28598 (Hebrew ISO VISUAL).
 
Then I am able to read the info in its right format.
 
I need to do the same but using C#.
 
The first step, converting to codepage 862 is working fine, but gives me the Hebrew text inverted, instead of "hello" it gives me "olleh" (in Hebrew letters).
Thanks in advance for any help.
 
Here is the code:

  // STEP 1

  // read original unrecognized file with

  Encoding ecp862 = Encoding.GetEncoding(862);

  StreamReader sr862 = new StreamReader(openFileDialog1.FileName, ecp862, true);

  txtText01.Text = sr862.ReadToEnd();

  sr862.Close();

  // END STEP 1

 

  // METHOD 1 FOR STEP 2

  // copy to txt file

  StreamWriter sr = new StreamWriter(@"c:\\temp\\ecp862.txt");

  sr.Write(txtText01.Text);

  sr.Close();

 

  // reading txt file

  Encoding ecp28598 = Encoding.GetEncoding(28598);

  StreamReader sr28598 = new StreamReader(@"c:\\temp\\ecp862.txt", ecp28598, true);

  txtText02.Text = sr28598.ReadToEnd();

  sr28598.Close();

  // END METHOD 1

 

  // METHOD 2 FOR STEP 2

  Encoding ecp28598_2 = Encoding.GetEncoding(28598);

  // Convert the string into a byte[].

  byte[] ecp862Bytes = ecp862.GetBytes(txtText01.Text);

 

  // Perform the conversion from one encoding to the other.

  byte[] code28598Bytes = Encoding.Convert(ecp862, ecp28598_2, ecp862Bytes);

 

  //Convert the new byte[]into a char[] and then into a string

  char[] code28598Chars = new char[ecp28598_2.GetCharCount(code28598Bytes, 0,          code28598Bytes.Length)];

 

ecp28598_2.GetChars(code28598Bytes, 0, code28598Bytes.Length, code28598Chars, 0);

  string code28598String = new string(code28598Chars);

  txtText03.Text = code28598String;

  // END METHOD 2