• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unicode value for char

 
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I want to show the unicode value of input character but it does not work
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please TellTheDetails ItDoesntWorkIsUseless
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Saloon Keeper
Posts: 15533
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will this be acceptable?
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 15533
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I want to understand unicode deeply.



Is there easier way to convert \u0633 to س

 
Stephan van Hulst
Saloon Keeper
Posts: 15533
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79240
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 . . .
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tom Reilly's second post in this topic shows how to do it.
 
Bring out your dead! Or a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic