I want to convert
\u0027 to '
\u00F1 to ñ, etc.
The requirement is : Handle Unicode escape sequence.
I was under an impression that StringEscapeUtils.unescapeJava will take care of everything but it did not.
I am looking for any other such method in java that can help me convert all such Unicode escape sequences.
By the way, perhaps you're unfamiliar with the word "encoding" that I used there. If so you should have a look at a tutorial which explains what encodings are used for in Java, such as this one: http://docs.oracle.com/javase/tutorial/i18n/text/convertintro.html
I'm assuming that StringUtils.replace(msg, s, "n") is meant to behave the same way but we have no way of knowing for sure unless we see the source code for that method. If they are indeed the same, then I'd have to start suspecting that it has something to do with OP's system.
and let us know what it prints. Also, where do you see the output from System.out? Are you using a Windows command line or do you see the output in an IDE of some kind, like Eclipse or Netbeans?
You could also do this:
and see if you get "t?d" for that.
It would also help to know the encoding (or charset) which your text editor used to write the file which contains the source code which you're asking about.
Tiya Khambadkone wrote:
What I meant was that these three lines are EXACTLY the same to the Java compiler. The output of all three lines will be the same:
Are you sure you're using a plain text editor? Don't use WordPad or whatever is the default Windows editor. Use NotePad if you don't have a proper Java IDE like Eclipse.
Line 4 should definitely compile and it will compile as if it were written as either one of the previous lines.
Tiya Khambadkone wrote:These are the outcomes :
Tiya, STOP. Take a breather and chill out.
From what I see (and I might be wrong), you don't properly understand what your library methods actually do.
My clue came from this post (slightly edited):
Tiya Khambadkone wrote:I did the following :
Output is :
That tells me that StringEscapeUtils.escapeJava() returns the Unicode escape string for the character(s) in the supplied string.
In your case, you supplied a String containing ONE character; '\u00F1' - or 'ñ'; and it returned you a SIX-character String containing the character '\', followed by "u00F1", which it duly printed out for you.
However, that String, which is "\\u00F1" - a SIX-character string - will NEVER be equal to "\u00F1", which is a ONE-character string.
Tiya Khambadkone wrote:thank you all. I appreciate your efforts in helping me out.
However, I am still stuck at my very basic question. i.e. what is the solution ?
To what? I've just told you why your code won't work.
We're happy to help, but we won't do your work for you.
Try changing your IDE settings to UTF-8 or ISO-8859-1 if it's not already that. After you change the settings, you might want to try some of the simple statements we already gave before that we know should work. Create new programs when you try those, don't use the programs you're already have trouble with.