• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

how can I assign a unicode value to a char variable?

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont know why the compiler give me wrong message which says:
Invalid character constant.
public class ADirtyOne
{
char a = '\u000a';
}

then How can assign a unicode value to a char variable?
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi James,
I believe that's exactly how you would described a Unicode character. The fact that the compiler gives an error is because the compiler will parse the "\u000a" itu a CR (or LF, I forget.. ).. that's why it's a compiler error when it's trying to parse:
char a='<CR>';
but, if you try to define a non-reserved character
char a='\u0031';
you won't get that error..
some other Unicode that will give the compiler a headache is like \u000d, or any other operators used in Java (';','"',etc.)
- eric
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just remember that in order to avoid errors when assigning unicode values to chars, each unicode value must be exactly four hexidecimal digits (e.g. in '\u???', the question marks are replaced with the unicode value, which are digits).
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The discussion of why \u000a doesn't work has been held severla times. Do a search for \u000a in this forum.
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pls follow this link ... this question has been answered very precisely here
hope that helps
Samith.P.Nambiar
<pre>
\```/
(o o) harder u try luckier u get
-------oOO--(_)--OOo----------------------------
</pre>
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic