The Singhology's Blog

Unescape unicode \\ in Java String

Posted in Java by jsinghfoss on August 17, 2011

I ran into a problem where my unicode slashes (\\) were not escaped properly. I had the following unicode string in a java variable:

\\u0011\\u00FF\\u0000\\u0001

To get correct 4 bytes out of this unicode string you must use StringEscapeUtils.unescapeJava(unicodeString) available inside Apache’s Common Lang jar.

The method will correctly edit the above unicode string into:

\u0011\u00FF\u0000\u0001

So, on calling getBytes() on your new unescaped string you will get 4 bytes.

Advertisement
Tagged with: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.