Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Maybe making the string Unicode.

Similar problem with a Google Translator program I found here on CodeProject...

What I have tried:

using (StreamReader SR = new StreamReader(@"C:\Users\john\Dropbox\germanWords.txt"))
            {
                while (!string.IsNullOrWhiteSpace(s=SR.ReadLine()))
                {
                    try
                    {
                        l.Add(new ListOfWordsApp.FormMain.wordAndMeaning(
                            s.Substring(0, s.IndexOf("-")),
                           s.Substring(s.IndexOf("-") + 1)));
                    }
                    catch
                    {
                        MessageBox.Show(s);
                    }
                }
            }
Posted
Updated 25-Feb-17 7:46am
Comments
Philippe Mori 25-Feb-17 13:35pm    
Most probable reason is that you must specify which encoding is used for your file.

1 solution

When you create a StreamReader using the simplest constructor - providing only the filepath - it is opened by default assuming UTF8 encoding-if your text file is not encoded in UTF8 then it's unlikely that any "non-English" characters such as those with an umlaut will be picked up correctly. You can specify the encoding: StreamReader Constructor (Stream, Encoding) (System.IO)[^] but I'd start by having a good look at your input data and it's source before I went too far to makesure that the characters you arelooking for aren't already "corrupted".
 
Share this answer
 
Comments
john1990_1 25-Feb-17 14:00pm    
The link is complicated, would you please tell me what to write in order to make a Unicode streamreader?
EDIT:
I used:
using (StreamReader SR = new StreamReader(@"C:\Users\rabea\Dropbox\germanWords.txt", UnicodeEncoding.Unicode))

and made the file encoding Unicode, it works.

thx a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900