I am using Jre 1.6.
I am executing the following lines of code:
String unicodeValue = “\u001B”; text = text.replaceAll(“” + character, unicodeValue);
Here, text is a string object containing an invalid XML character of Unicode value ‘\u001B’.
So, I am converting the invalid XML character to its Unicode value to write in the XML.
But on doing text.replaceAll, the ‘\’ is getting stripped and the character is replaced by ‘u001B’.
Can anyone please suggest a way to retain the ‘\’ after replacing the character with its unicode value ?
The problem is that
str.replaceAll(regex, repl)is defined as returning the same asBut the documentation for
replaceAllsays,So this means we need to add several extra layers of escaping:
prints
invalid\u001Bstringas desired.