0

I create a text file with ANSI format and write persian word in that, now I read that with this code:

System.Net.WebClient wc = new System.Net.WebClient();
string textBoxNewsRight2Left = wc.DownloadString("http://dl.rosesoftware.ir/RoseSoftware%20List/Settings/News.Settings.txt");
MessageBox.Show(textBoxNewsRight2Left);

but I see ???????????????????? character!

I change file format to UTF8 and my problem fix with persian word, but again I find another problem this time with english word!

once again I use from this codes with UTF8 format file:

System.Net.WebClient wc = new System.Net.WebClient();
string textBoxNewsRight2Left = wc.DownloadString("http://dl.rosesoftware.ir/RoseSoftware%20List/Settings/News.Settings.txt");
MessageBox.Show(textBoxNewsRight2Left);

Now I see: "ÿþr" and I don't see my file words!

Now I use:

wc.Encoding = Encoding.Unicode;

Now I see my file words! without "ÿþr".

I don't think I have in original file hello and after read by C# I have hello now I test equaling textBoxNewsRight2Left and hello

                if (textBoxNewsRight2Left == "hello")
                {
                    MessageBox.Show("Equal");
                }
                else
                {
                    MessageBox.Show("Not Equal");
                }

Now I see message Not Equal, but I see hello!

what is the problem?

I how can fix this problem?

EBH
  • 10,350
  • 3
  • 34
  • 59
  • I did not remember an Ansi format for arabic/farsi. Just use unicode, e.g. utf-8 – Roland Jul 23 '16 at 23:15
  • What is your purpose? Why a txt file, why not a html doc with proper utf-8 indication? How is WebClient to know the document encoding? If you have an html doc, try to validate it on the w3.org site, there it will check the encoding. – Roland Jul 23 '16 at 23:22

0 Answers0