• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help required : unicode representation  RSS feed

 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All ,

I am trying to use thai characters with their unicode values.

As far as I know, this can be done by prepending '\u', to the unicode values. (eg, \u0e04)
If I do it this way,
String thaiMsg = "\u0e04";
System.out.println(thaiMsg);
this works perfectly, but in my case, this 0e04 is not static, I get it dynamically, so what I am doing now is :
String unicode = "0e04"; //value available from some function
String thaiMsg = "\\u" + unicode;
System.out.println(thaiMsg);
Now, just see the output of the string printed in both the above cases and see the difference.

Is there some solution to this problem?

Is there some other way of representing the character with its unicode value ?

Ankit
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "\uxxxx" format is for compile time constants - it is translated by the compiler.
For dynamic string building you can use a char or int variable.
(right off the top of my head)
int someInt = 0x0e04 ;
char myThai = (char) someInt ;
String thaiMsg = "" + myThai ;
or
String thaiMsg = Character.toString( myThai );
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!