KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to read unicode string from a console in C#, for the sake of example, lets uset his one: c:\SVN\D³ebugger\src\виталик\Program.cs At first I just tried to Console.ReadLine() which returned me c:\SVN\D3ebugger\src\???????\Program.cs I've tried to set the Console.InputEncoding to UTF8 like so Console.InputEncoding = Encoding.UTF8 but that returned me c:\SVN\D³ebugger\src\???????\Program.cs , basically mucking up the Cyrillic part of the string. So randomly stumbling I've tried to set the encoding like that, Console.InputEncoding = Encoding.GetEncoding(1251); which returned c:\SVN\D?ebugger\src\виталик\Program.cs , this time corrupting the ³ character. At this point it seems that by switching encodings for the InputStream I can only get a single language at a time. I've also tried going native and doing something like that: // Code public static string ReadLine() { const uint nNumberOfCharsToRead = 1024; StringBuilder buffer = new StringBuilder(); uint charsRead = 0; bool result = ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE), buffer, nNumberOfCharsToRead, out charsRead, (IntPtr)0); // Return the input minus the newline character if (result && charsRead > 1) return buffer.ToString(0, (int)charsRead - 1); return string.Empty; } // Extern definitions [DllImport("Kernel32.DLL", ExactSpelling = true)] internal static extern IntPtr GetStdHandle(int nStdHandle); [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)] static extern bool ReadConsoleW(IntPtr hConsoleInput, [Out] StringBuilder lpBuffer, uint nNumberOfCharsToRead, out uint lpNumberOfCharsRead, IntPtr lpReserved); That was working fine for non-unicode strings
Tags (comma-separated)
Save Edits
Cancel