Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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 representation of char

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any body explain me the unicode representation of char .

char c = '\uface' ; // is perfect , why ?
char c1 = '\u000a' ; // is wrong , why ?
char c2 = '\u000d' ; // is wrong , why ?
char c3 = '\u000b' ; // is perfect , why ?

Although I know the answer of 2nd & 3rd but how can one remember what is right & what is wrong ...

char c4 = '\uabcd' ; // what right or wrong ???

please help .

thanks .
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not use the Unicode characters \u000a or \u000d. Instead use \n or \r. The reason is that these Unicode values are converted into the actual characters very early in the compile process. Later, when javac breaks your source code into lines and tokens, these characters are treated as actual newline characters and break your statement into 2 lines divided by white space.
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No but , How I will know about first one ... or any other like last one ..

thanks .
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use \u000a or \u000d in your source code, use \n or \r. These are the only two cases like that. A Unicode character is \u followed by 1-4 hex digits. Each hex digit is 0-9 or a-f or A-F. They don't all have graphics, certainly not in any one language, but you aren't going to memorize all of them anyway.

Character literals look like:
final char A = '\u0041';

String literals can contain Unicode like:
final String ABC = "\u0041\u0042\u0043";
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Mike .
I got the point .
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A Unicode character is \u followed by 1-4 hex digits.

Hey mike ,

one correction in this ...

\u followed by exactly 4 hex digit not 1-4 hex digit .

am i right ?
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, Just in case if you dont know.
Just remember "big farms need red tractors".

The escape sequences are as follows: '\b' (backspace), '\f' (formfeed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\\' (backslash), '\"' (double quote), '\'' (single quote). Yes, you must memorize the escape sequences!

Thanks a ton to Dan G.

~Swapnil
[ January 04, 2005: Message edited by: Swapnil Sapar ]
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't get Swapnil this ...
can you please put some light on this ...

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

\u followed by exactly 4 hex digit not 1-4 hex digit .

am i right ?



Yes.


Thanks, Rathi, I didn't know that.

Mike
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic