简体   繁体   中英

How to read input in UTF-8 in c# using Console.readLine?

I want to take the input in UTF-8 character encoded using Console.ReadLine() or any other method in C#. In java I have found this

Scanner in = new Scanner(System.in, "utf-8");

I'm getting this output: I0NISMS4QhiSWnSIADCAXg

But the expected output is this type: {"result": 5, "id": 1}

just set the Console.OutputEncoding to UTF-8 :

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

for example :

static void Main(string[] args)
{
    Console.OutputEncoding = System.Text.Encoding.UTF8;

    using (StreamReader reader = new StreamReader("test1.txt",System.Text.Encoding.UTF8))
    {
        string line;

        while ((line = reader.ReadLine()) != null)
        {
            Console.WriteLine(line);
        }

    }

    Console.ReadLine();
}

AND also configure your console font such this:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM