2

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}

3
  • Perhaps try Console.InputEncoding. Commented Jun 27, 2015 at 12:01
  • Tried but not worked Commented Jun 27, 2015 at 12:03
  • That is a base64 encoded string, it has nothing whatsoever to do with the console or utf8. The binary data encoded in that string does not have a recognizable match with the json style output you like. Commented Jun 27, 2015 at 12:35

1 Answer 1

2

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:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

i don't wan't to read input from file i'want to take it from user

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.