I have a line like this
"\x27\x18\xf6,\x03\x12\x8e\xfa\xec\x11\x0dHL"
when I put it in the browser console, it automatically becomes something else:
"\x27\x18\xf6,\x03\x12\x8e\xfa\xec\x11\x0dHL" "'รถ,รบรฌHL"
if I do chatAt(x) on this line, 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) "รถ"
what I want.
Now I want to implement a Java program that reads a string in the same way as in a browser.
The problem is that Java does not recognize the encoding method of this string. Instead, it treats it like a regular 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 encoding is encoded by this string? What encoding uses the \x prefix? Is there a way to read it correctly (get the same result as in the browser)?
update: I found a solution -> I think this 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 answers :) especially Ricardo Casheri
thanks