I have a string like this

"\x27\x18\xf6,\x03\x12\x8e\xfa\xec\x11\x0dHL"

when i put it in browser console, it automatically becomes something else:

"\x27\x18\xf6,\x03\x12\x8e\xfa\xec\x11\x0dHL"
"'ö,úìHL"

if I do chatAt(x) over this string, I get:

"\x27\x18\xf6,\x03\x12\x8e\xfa\xec\x11\x0dHL".charAt(0)
"'"
"\x27\x18\xf6,\x03\x12\x8e\xfa\xec\x11\x0dHL".charAt(1)
""
"\x27\x18\xf6,\x03\x12\x8e\xfa\xec\x11\x0dHL".charAt(2)
"ö"

which IS what I want.

Now I want to implement a Java program that reads the string the same way as in browser.

The problem is, Java does not recognize the way this string is encoded. Instead, it treats it as a normal string:

"\\x27\\x18\\xf6,\\x03\\x12\\x8e\\xfa\\xec\\x11\\x0dHL".charAt(0) == '\'
"\\x27\\x18\\xf6,\\x03\\x12\\x8e\\xfa\\xec\\x11\\x0dHL".charAt(1) == 'x'
"\\x27\\x18\\xf6,\\x03\\x12\\x8e\\xfa\\xec\\x11\\x0dHL".charAt(2) == '2'

What kind of encoding this string is encoded? What kind of encoding uses prefix \x? Is there a way to read it properly (get the same result as in browser)?

update: I found a solution -> i guess it is not the best, but it works for me:

StringEscapeUtils.unescapeJava("\\x27\\x18\\xf6,\\x03\\x12\\x8e\\xfa\\xec\\x11\\x0dHL".replace("\\x", "\\u00"))

thank you all for your replies :) especially Ricardo Cacheira

Thank you

Edit
Report