0

I have a string which might have already been escaped. I want to unescape it and get the string in UTF-8.

I am thinking of applying all the unescape functions from Apache commons lang StringEscapeUtils

My question is will it have any effect in the order in which the unescape functions will be applied and also can I apply all the unescape functions without it affecting the final output?

Sudar
  • 18,954
  • 30
  • 85
  • 131
  • What happens when you ... *try it* ? – Brian Roach May 16 '13 at 17:48
  • I tried it in a sample file and it seems to have not caused any issues. But the final data in which I will be applying this is not available with me now. So that's why I wanted to know whether using all unescaping functions will have any effect or not. – Sudar May 16 '13 at 17:52
  • has already been answered i think **http://stackoverflow.com/questions/3537706/howto-unescape-a-java-string-literal-in-java** – Adam Garner May 16 '13 at 17:56

1 Answers1

0

The StringEscapeUtils are meant to be used in pairs: if you use escapeXML you should use unescapeXML to get the original string. That being said, if you are absolutely sure that your string is escaped using the correct formatting, you can use the unescape function. Always test this first.

Farlan
  • 1,860
  • 2
  • 28
  • 37
  • My problem is that I have no idea about the input data. It *might* have got escaped or not :( – Sudar May 16 '13 at 17:56
  • If you don't know your input how can you ever verify your output? Best to start with some assertions. You can use a DOM parser to just verify that it's legit XML before escaping it – Christian Bongiorno May 16 '13 at 18:27