Using Unicode in input variables problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everyone,

I'm trying to output (in Unicode) a variable read in by the program in its
"\u1234" format. I know I can successfully output Unicode values because when
I hardcode a string variable it works fine, as in:

WORKING:
string myUnicodeString = "Hello \u1234 World";
Console.Out.WriteLine(myUnicodeString);

NOT WORKING:
string myUnicodeString2 = Console.ReadLine();
// user then enters: Hello \u1234 World
Console.Out.WriteLine(myUnicodeString2);

I know I'm probably doing something definitely wrong here, but can anyone
guide me on how I might be able to fix this problem?

Thanks for any help!
 
Beyondtron said:
Hi everyone,

I'm trying to output (in Unicode) a variable read in by the program in its
"\u1234" format. I know I can successfully output Unicode values because when
I hardcode a string variable it works fine, as in:

WORKING:
string myUnicodeString = "Hello \u1234 World";
Console.Out.WriteLine(myUnicodeString);

NOT WORKING:
string myUnicodeString2 = Console.ReadLine();
// user then enters: Hello \u1234 World
Console.Out.WriteLine(myUnicodeString2);

I know I'm probably doing something definitely wrong here, but can anyone
guide me on how I might be able to fix this problem?

\u1234 is interpreted when you compile the code, i.e. it's actually
part of the syntax, like \n and \t. The input from console is
interpreted according to its code page. So that you have to translate
the \uXXXX string by yourself.
 
Back
Top