I often have to escape many quotation marks in a String. Is there a library that provides String functions such as this. It's easy enough to write, but something that had lots of different features/options for escaping would be handy.
Asked
Active
Viewed 781 times
3 Answers
4
Apache Commons has a StringEscapeUtils
class which is able to escape (and unescape) in the following formats:
- CSV
- HTML
- Java
- JavaScript
- SQL
- XML

aioobe
- 413,195
- 112
- 811
- 826
0
It depends on the context in which you're escaping the quotation marks. Usually, it should be handled by a task-specific library. For example, if you're escaping quotes for use in an SQL string, you should be using parameter placeholders instead of concatenating the string. If you're escaping quotes for use in a JSP, you should use <c:out>
which will deal with quotes and other HTML entities.

artbristol
- 32,010
- 5
- 70
- 103