locked
reading string from text file in Hebrew - (C#) RRS feed

  • Question

  • Hello

    I am reading a text file in hebrew.

    When I try to write what I read ' I get garbage instead of hebrew text. The same code 

    works fine for english text. What should I do  ?

    Here is the code :

                TextWriter w1 = new StreamWriter("out_classes.txt");

                using (StreamReader r1 = new StreamReader("inp_classes.txt")) {

                    string line;

                    while ((line = r1.ReadLine()) != null) {

                        w1.WriteLine(line);

                    }

                    r1.Close();

                }

                w1.Close();

            }

    The input:

    this is english line 

    also another second line 

    ז1 33 זאת כיתה זזזזז1111

    ז2 33 ז2 ז2 ז2 

    זמחוננים 34 

    ח1 35

    ח2 35

    חמחוננים 36חמחוננים חמחוננים

    סתפםסתםס

    סתם

    סתם

    סתם  

    the result :

    this is english line 

    also another second line 

    �1 33 ��� ���� �����1111

    �2 33 �2 �2 �2 

    �������� 34 

    �1 35

    �2 35

    �������� 36�������� ��������

    ��������

    ���

    ���

    ���  

     

     


    good morning sunshine
    Wednesday, May 25, 2011 1:17 PM

Answers

  • thanks

     

    I found it :

    TextReader txt1 = new StreamReader(fd.FileName, Encoding.Default);


    good morning sunshine
    Wednesday, May 25, 2011 8:13 PM

All replies

  • I think issue with the encoding. Try using overloaded streamReader class by passing the Encoding.

    • Proposed as answer by Krishnav Thursday, May 26, 2011 5:32 PM
    Wednesday, May 25, 2011 1:53 PM
  • thanks

     

    I found it :

    TextReader txt1 = new StreamReader(fd.FileName, Encoding.Default);


    good morning sunshine
    Wednesday, May 25, 2011 8:13 PM
  • It seems it has to be

    Encoding.UTF8


    good morning sunshine
    Monday, June 20, 2011 9:48 PM