File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unicode value for char

 
abalfazl hossein
Ranch Hand
Posts: 635
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I want to show the unicode value of input character but it does not work
 
Mohamed Sanaulla
Saloon Keeper
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please TellTheDetails ItDoesntWorkIsUseless
 
Tom Reilly
Rancher
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 635
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 4840
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 635
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will this be acceptable?
 
abalfazl hossein
Ranch Hand
Posts: 635
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 4840
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 635
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I want to understand unicode deeply.



Is there easier way to convert \u0633 to س

 
Stephan van Hulst
Bartender
Pie
Posts: 4840
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 635
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47292
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 . . .
 
Lovro Bajc
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone. I have a far more beginners question I guess.

currently I am at the 4th section in the book called Introduction to Java programming, comprehensive version 10, by Y.Daniel Lang.

I have a task to print out the unicode of the entered character by user. Here is the code so far:


I dont know/ have no clue how to get the value out for a character.

Can you please assist me on this problem.

thanks for your time, review and answer.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Reilly's second post in this topic shows how to do it.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic