Using Unicode in input variables problem

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!
 
A

Aquila Deus

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top