- Escapes the characters in a
String
using Java String rules - Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
- So a tab becomes the characters
'\\'
and't'
. - The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote must be escaped.
- package com.utilitySample;
- import org.apache.commons.lang.StringUtils;
- public class StringUtility {
- public static void main(String[] args) {
- String inputStr = "sample jav\ta escape";
- System.err.println("After escape ::"+StringEscapeUtils.escapeJava(inputStr));
- System.err.println("After unescape ::"+StringEscapeUtils.unescapeJava(inputStr));
- }
- }
After escape ::sample jav\ta escape
After unescape ::sample jav a escape
After unescape ::sample jav a escape
No comments:
Post a Comment