David MacNeil
David MacNeil

Reputation: 126

Adding escape to String, possible?

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.

Upvotes: 1

Views: 74

Answers (1)

k_g
k_g

Reputation: 4464

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

Upvotes: 4

Related Questions