Here you can find the source of unescapeString(String escapedString)
Parameter | Description |
---|---|
escapedString | the string containing escapes |
public static String unescapeString(String escapedString)
//package com.java2s; public class Main { /**//from ww w .jav a 2s. c o m * Replaces all the printf-style escape sequences in a string * with the appropriate characters. * * @param escapedString the string containing escapes * @return the string with all the escape sequences replaced */ public static String unescapeString(String escapedString) { StringBuffer sb = new StringBuffer(); for (int i = 1; i < escapedString.length() - 1; ++i) { char c = escapedString.charAt(i); if (c == '\\') { ++i; sb.append(unescapeChar(escapedString.charAt(i))); } else { sb.append(c); } } return sb.toString(); } private static char unescapeChar(char escapedChar) { switch (escapedChar) { case 'b': return '\b'; case 't': return '\t'; case 'n': return '\n'; case 'f': return '\f'; case 'r': return '\r'; default: return escapedChar; } } }