• 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

char assignation unicode

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can somebody explain how to assign a char variable with the simple quote (') using the unicode character \u0027 and escape character \,in order to reach the same value of c1?
char c1='\''; //OK
char c2='\u005c\u0027'; /* OK-> like c1 */
char c3='\'\u0027; //OK ->like c1 and c2
My idee was:
char c4='\\u0027'; //doesn't compile
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
El Daniel,
In fact, your problem is the first line :
char c1='\''; //OK
It�s not ok, because you started another literal string and didn�t finished it...
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The char assignment has "too many characters in the character literal" in the assignment, char c = '\\u0027';.
As you can't do

it is not possible to assign

The reason is, your first escape escapes the second one. What I mean is, it would have been perfectly ok if you have said,

And the resultant \ is not goin to be the escape part of the following u0027
So, you can see the rest of the characters are not valid for a char primitive type.
This escape business gave me headache for a while. Jose helped me out on one occasion. Here is the link if you're interested:
https://coderanch.com/t/240199/java-programmer-SCJP/certification/unicode-escapes
[ December 12, 2002: Message edited by: Abu Yoosuf ]
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you cannot have two backslash together & add ur unicode, so better do what you did for c2 or what I did for c4 in the following code.

o/p is
true
true
true
[ December 12, 2002: Message edited by: shweta mathur ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic