2

Thank you very much for all the help till now.

I have the following problem:

 static void Main(string[] args)

    {
        Dictionary<string, string> dict = new Dictionary<string, string>();

        using (StreamReader reader = new StreamReader(@"C:\test.csv"))
        {
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                string[] parts = line.Split(',');
                dict.Add(parts[0],parts[1]);
            }
        }
        Console.WriteLine("enter name:");
            string name  = Console.ReadLine();
            if (dict.ContainsKey(name))
            {
                //
                string value = dict[name];
                Console.WriteLine(dict[name]);//value);
            }
            Console.ReadLine();

    }
}

And this is my Outout:

enter name:
ILIA
????

This is my CSV file content

ILIA,ИЛИЯ

Can you please help me out clear this ???? and get the correct symbols in Cyrillic?

Thank in advance for any help!

Ilia

Ilia Lazarov
  • 43
  • 1
  • 7
  • 1
    This is either a file *encoding* issue (pass the right `Encoding` to `StreamReader`), or a console output issue (set `Console.OutputEncoding` to something that supports Cyrillic). Make sure your console uses a Cyrillic-enabled font as well. – Lucas Trzesniewski Jul 09 '15 at 21:20

3 Answers3

1

Try :

StreamReader reader = new streamReader(@"C:\test.csv",Encoding.GetEncoding(1251)) ;
Graffito
  • 1,658
  • 1
  • 11
  • 10
0

The output encoding of your console is likely set to ASCII. Try adding the following command before writing to the console:

Console.OutputEncoding = System.Text.Encoding.Unicode;

It's also possible that the the font that you chose for the console does not support Unicode. To fix this, open the the command console, click on the icon at the top left corner of the window that says "C:\". Select properties. Select Font. Try selecting a different font.

0

I noticed this unpleasant issue while reading files with Cyrillics some time ago. The easiest solution - open the file in Notepad++ or any similar text editor that can change encoding and choose from the menu Encoding -> Convert to UTF-8 for example. Then your file will be processed correctly with your code

Serhiy Chupryk
  • 438
  • 2
  • 5
  • 15