| Author |
char value
|
pradeepta chopra
Ranch Hand
Joined: Jul 05, 2008
Posts: 137
|
|
class A{ public static void main(String[] args) { char c='\u123'; System.out.println(c); } } output: ? why does it gives the above output?? and how can i print the unicode value for a given character??? thanks
|
 |
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
may this links helps you to understand the concepts OR googled it ! [ August 13, 2008: Message edited by: Sagar Rohankar ]
|
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
|
 |
Stephen Davies
Ranch Hand
Joined: Jul 23, 2008
Posts: 352
|
|
I think perhaps it gives a ? because u123 is an invalid Unicode character. At least, I'm getting that error in Eclipse. Have a look here for a good Unicode table. http://www.tamasoft.co.jp/en/general-info/unicode.html (The page may take some time to load so be patient) [edit]Corrected UBB tags. CR[/edit] [ August 13, 2008: Message edited by: Campbell Ritchie ]
|
be a well encapsulated person, don't expose your privates, unless you public void getWife()!
|
 |
Stephen Davies
Ranch Hand
Joined: Jul 23, 2008
Posts: 352
|
|
<a href=http://www.tamasoft.co.jp/en/general-info/unicode.html ]http://www.tamasoft.co.jp/en/general-info/unicode.html>http://www.tamasoft.co.jp/en/general-info/unicode.html ]http://www.tamasoft.co.jp/en/general-info/unicode.html</a>
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
If you look it up in Unicode (look for file U0100.pdf), you find it says this:
ģ 0123 LATIN SMALL LETTER G WITH CEDILLA � Latvian � there are three major glyph variants ≡ 0067 g 0327 $̧
And when I tried it on a Bash shell (Linux) I got this output:
javac Print123.java campbell@linux-pgix:~/java> java Print123 ģ campbell@linux-pgix:~/java>
So the problem might be that your terminal window won't support all the Unicode characters; I find Windows or DOS often fails to print non-ASCII characters.
|
 |
pradeepta chopra
Ranch Hand
Joined: Jul 05, 2008
Posts: 137
|
|
|
thanks for the above refrences and can you please tell me if there is a method through which i may be able to print the unicode values of characters??
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
|
By the way, it's not '\u123' but '\0123'. '\u123' doesn't seem to compile. I knew to try \u0123 first, but in future, please Post Real Code with ctrl-c ctrl-v.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
|
It works nicely on Eclipse when you have 4 (hexadecimal) numbers after the \u. That's the problem.
|
 |
Norm Radder
Ranch Hand
Joined: Aug 10, 2005
Posts: 681
|
|
Look at the Integer class. It has methods to convert int to hex. Then prepend the \u with some 00s to it.
|
 |
pradeepta chopra
Ranch Hand
Joined: Jul 05, 2008
Posts: 137
|
|
well i even tried '\u0123' but it still prints ? maybe windows do not support the char even if i say '\u0000' it doesnt print a 0, it simply doesnt prints anything. so what do we do if theres such a question in the exam that asks for the output it seems to be implementation dependent
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
I have already told you Windows/DOS tends not to support non-ASCII characters; I have sometimes had problems with characters in the range 0x80 to 0xff. And '\u0000' isn't "0"; it is the null character, so you wouldn't expect anything to appear.
|
 |
pradeepta chopra
Ranch Hand
Joined: Jul 05, 2008
Posts: 137
|
|
ok thankyou
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
You're welcome
|
 |
 |
|
|
subject: char value
|
|
|