Here you can find the source of unescapeText(String s)
Parameter | Description |
---|---|
String | the String to be unescaped |
public static String unescapeText(String s)
//package com.java2s; //License from project: LGPL public class Main { /**//from w w w . j a va 2s. c o m * Replaces &-excape sequences required by HTML and XML with the character represented by the * escape sequence (& < > " and '). * @param String the String to be unescaped * @return a string witht the escaped characters replaced with the above characters */ public static String unescapeText(String s) { StringBuffer sb = new StringBuffer(); int oldIndex = 0; int index = s.indexOf('&'); while (index >= 0) { sb.append(s.substring(oldIndex, index)); if (s.startsWith("&", index)) { sb.append('&'); oldIndex = index + 5; } else if (s.startsWith("<", index)) { sb.append('<'); oldIndex = index + 4; } else if (s.startsWith(">", index)) { sb.append('>'); oldIndex = index + 4; } else if (s.startsWith(""e;", index)) { sb.append('"'); oldIndex = index + 7; } else if (s.startsWith("'", index)) { sb.append('\''); oldIndex = index + 6; } else { sb.append('&'); oldIndex = index + 1; } index = s.indexOf("&", oldIndex); } sb.append(s.substring(oldIndex)); return sb.toString(); } }