| Author |
unicode value for char
|
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
I want to show the unicode value of input character but it does not work
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2927
|
|
|
Please TellTheDetails ItDoesntWorkIsUseless
|
Mohamed Sanaulla | My Blog
|
 |
Tom Reilly
Rancher
Joined: Jun 01, 2010
Posts: 618
|
|
|
System.in.read() reads a byte, not a char (a char is two bytes). To show this, try running the following code:
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
Thanks tom,
I want the code show this: "\u0633",But it doesn't
This is output of your code:
please enter a char
س
numRead = 2
-45 10 please enter a char
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3047
|
|
|
Remember, for character data we don't use InputStream, we use Reader. Wrap a Reader around System.in, using the correct encoding, and then you can read one character at a time.
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
Thank you
Look at this code:
The output is :
س
Now my question:
I want that code return \u0633 when I enter س I had posted.
It java itself convert \u0633 to س, Then why it couldn't convert س to \u0633
This is code that I wrote:
ouput:
633
I want it shows this "\u0633" without add "u" or "\" in the program, by programmer.
|
 |
Tom Reilly
Rancher
Joined: Jun 01, 2010
Posts: 618
|
|
|
Will this be acceptable?
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
What is the simplest way in java in order to convert unicode to character?
\u0633 conver to س
Is this correct:
UTF8 is a standard for unicode encoding.
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3047
|
|
Abalfazl, I get the impression you are confused about the meaning of \u0633.
Any of the \uxxxx tokens in Java source code will be read by Java's 'precompiler', and automatically converted to their char representation. This all happens before the source code is actually compiled. This is done in the entire file, including comments, strings and other code.
It's simply a way you can enter unicode characters in your source file without being able to type their actual character representation. Outside of the precompiler, these tokens have no meaning.
There is no simplest way of converting \u0633 to س, because they already mean exactly the same thing, as far as Java in concerned.
What is it exactly you want to do?
As for your question regarding UTF-8, what have you found out for yourself?
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
Thanks, I want to understand unicode deeply.
Is there easier way to convert \u0633 to س
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3047
|
|
|
What do you mean by convert? To print the graphical glyph representing the unicode character? Then no, this should be simple enough.
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
I have question about this line:
This prototype is from:http://download.oracle.com/javase/1.4.2/docs/api/java/io/PrintStream.html
Is System.out instance of OutputStream?May you explain about the this redirect mechanism?
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12921
|
|
abalfazl hossein wrote:Is System.out instance of OutputStream?
You can find the answer to this question in the documentation of class java.lang.System.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32665
|
|
Jesper de Jong wrote:
abalfazl hossein wrote:Is System.out instance of OutputStream?
You can find the answer to this question in the documentation of class java.lang.System.
. . . or . . .
|
 |
 |
|
|
subject: unicode value for char
|
|
|