Loading international characters from a text file

I have a list of words which contain exotic characters :


These words are in a textfile.

When I make a console program and I read the file like :

// ----------------- simple console application -------------------

string sFile= @"c:\data\junk\listexoticsigns.txt";

  static void Main(string[] args)
    MainClass MC = new MainClass ();

          using (var SR = new StreamReader (MC.sFile)) {
                while (!SR.EndOfStream) {
        Debug.Print (SR.ReadLine());
       SR.Close ();

the exotic characters will be replaced by ?.

When I replace the intiating of the Streamreader by :

               using(var SR = new StreamReader (MC.sFile, System.Text.Encoding.Default))

The correct characters will be shown
Till so far so good

// ---------------------------- Xamarin Android ----------------------

Now when I do the same in Xamarin Android.

List ListPure = new List ();
string s;

using (var SR = new StreamReader (Assets.Open("listexoticsigns.txt"))) {

while (!SR.EndOfStream) {
    s = SR.ReadLine();
SR.Close ();



List ListFiltered = new List ();
string s;

using(var SRspec = new StreamReader( Assets.Open("listexoticsigns.txt"), System.Text.Encoding.Default))
{while (!SRspec.EndOfStream)
s = SRspec.ReadLine ();
ListFiltered.Add (s);
SRspec.Close ();

It absolutely does not matter. In both cases the characters are replaced by '?'
Also in 'Console.writeline' in Application Output

What is wrong here?


  • PeterDavisPeterDavis USMember ✭✭✭

    What is the actual encoding of the text file?

  • Thanks for the hint. I checked the text file in Notepad and saw encoding was ANSI.
    Did a 'save as' and saw it was ANSI.
    I changed the encoding to UTF-8 and that solved the problem.

Sign In or Register to comment.