Here you can find the source of unescape(String x)
Parameter | Description |
---|---|
x | operate on this String |
static public String unescape(String x)
//package com.java2s; public class Main { /**/*ww w . j a va 2 s. co m*/ * This finds any '%xx' and converts to the equivilent char. Inverse of escape(). * * @param x operate on this String * @return original String. */ static public String unescape(String x) { if (x.indexOf('%') < 0) { return x; } // gotta do it char[] b = new char[2]; StringBuilder sb = new StringBuilder(x); for (int pos = 0; pos < sb.length(); pos++) { char c = sb.charAt(pos); if (c != '%') { continue; } if (pos >= sb.length() - 2) { // malformed - should be %xx return x; } b[0] = sb.charAt(pos + 1); b[1] = sb.charAt(pos + 2); int value; try { value = Integer.parseInt(new String(b), 16); } catch (NumberFormatException e) { continue; // not a hex number } c = (char) value; sb.setCharAt(pos, c); sb.delete(pos + 1, pos + 3); } return sb.toString(); } }