aspose file tools*
The moose likes Java in General and the fly likes Unicode problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Unicode problem" Watch "Unicode problem" New topic
Author

Unicode problem

Marcus Liu
Greenhorn

Joined: Feb 13, 2003
Posts: 12
the unicode of 'A' is '\u0041';

org.apache.common.lang.CharUtils.unicodeEscaped('A') = \u0041 ,

System.out.print(new String("\u0041")); --> result is 'A'

but
1). System.out.println(new String(CharUtils.unicodeEscaped('A'))) --> resutl is \u0041 , why not 'A'?
2) CharUtils.unicodeEscaped('A').equals(new String("\u0041")) --> result is false , why not true ?

who know it ? thx
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
You're getting confused between Strings and string literals.

In a string literal \u0041 means the character A.

But CharUtils.unicodeEscaped('A') returns a String whose contents are the characters \, u, 0, 0, 4, and 1. That will not be unescaped when you use it as the argument of new String().


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Marcus Liu
Greenhorn

Joined: Feb 13, 2003
Posts: 12
Originally posted by Peter Chase:
You're getting confused between Strings and string literals.

In a string literal \u0041 means the character A.

But CharUtils.unicodeEscaped('A') returns a String whose contents are the characters \, u, 0, 0, 4, and 1. That will not be unescaped when you use it as the argument of new String().


Thx your reply , I have knew a little idea.
In my test :

CharUtils.unicodeEscaped('A').equals("\\u0041") is true

so

is there any way to convert "\\u0041" to "\u0041" ?
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by Marcus Liu:
is there any way to convert "\\u0041" to "\u0041" ?


Sorry, you're going to have to explain more clearly and carefully what you want to do here. Explain what's the contents of a String and what's a string literal.

Or perhaps take a step back and explain what the higher-level thing is that you are trying to achieve.
Marcus Liu
Greenhorn

Joined: Feb 13, 2003
Posts: 12
sorry .

I meet a little trouble with the below :

char sourceChar = 'A';
String charUnicode = org.apache.common.lang.CharUtils.unicodeEscaped('A'); (comment : charUnicode == "\\u0041")

String realString = new String(charUnicode);

I want to get the 'realString' is 'A'.

do I explain it clearly ?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Doesn't the CharUtils class have another method for converting back? I don't have it here and I don't really feel like hunting down its documentation on the Internet.

If it doesn't, then you can convert the last four of those six characters to a char like this:But if you think you need to do this, and you aren't writing a Java compiler or parser, you probably don't really need to do this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unicode problem