1

Say I have a String s = "50";, and I want to append "\u00" onto the front of the string.

Is this possible without throwing an Illegal unicode escape?

Thanks.

3
  • 1
    String s = 50 would not compile. Commented Mar 28, 2014 at 22:40
  • You mean String s = "50"; ? Pls check your question after you have posted. Commented Mar 28, 2014 at 22:46
  • @suninsky Yes that is what I mean. Commented Mar 28, 2014 at 22:47

1 Answer 1

4

In java, unicode escapes must be four digit. Use \u0000 Also String s = 50is invalid. Use String s = "50"

If you want the final result to be "\u0050", you have to realize that escapes only really exist at the source level. You'd have to do something like this to "append" the unicode modifier to the beginning of a String containing a number

s = new String(Character.toChars(Integer.parseInt(s,16));//16 because unicode is hex 
Sign up to request clarification or add additional context in comments.

4 Comments

I know, I am using pseudocode. I want the unicode vers of 50 by adding \u00 to the front of it.
@FriarBob see the edit... escapes cannot be manipulated at runtime, they are controlled by the compiler
So if one of my Unicode chars is 6e there is nothing I can do?
Sorry, I forgot there for a second that unicode is hex... silly me. use Integer.parseInt(s,16);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.