Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# Linq doesn't recognize Czech characters while reading from .csv file

Basically, when trying to get a .csv file into a list using Linq, all characters with diacritics turn into <?> character. What should i do to make the code keep them as in the .csv file?

using (StreamReader ctec = new StreamReader(souborovejmeno))
            {
                var lines = File.ReadAllLines(souborovejmeno).Select(a => a.Split('\t'));
                var csv = from line in lines
                          select (from piece in line
                          select piece).ToList();

                foreach (var c in csv)
                {
                    hraci.Add(new Hrac(c[0], c[1]));
                    listBox1.Items.Add(c[0]);
                }
            }

Thanks in advance for answers. Sorry if this is quite dumb, i am not too experienced in coding.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try to include an encoding like that:

var lines = File.ReadAllLines(path, Encoding.UTF8).Select(a => a.Split('\t'));

Make sure to import System.Text

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading