Here you can find the source of htmlSpecialChars(String handleStr)
Parameter | Description |
---|---|
handleStr | a parameter |
public static String htmlSpecialChars(String handleStr)
//package com.java2s; //License from project: Apache License public class Main { public static boolean blnTextBox = true; /**//ww w . j a v a2 s . co m * htmlspecialchars, Change HTML special char in String * * @param handleStr * @return String */ public static String htmlSpecialChars(String handleStr) { return htmlSpecialChars(handleStr, true); } public static String htmlSpecialChars(String handleStr, boolean seq) { String str = handleStr; if (seq) { str = replace(str, "&", "&"); str = replace(str, "\"", """); str = replace(str, "<", "<"); str = replace(str, ">", ">"); } else { str = replace(str, "&", "&"); str = replace(str, """, "\""); str = replace(str, "<", "<"); str = replace(str, ">", ">"); } if (!blnTextBox) if (seq) str = replace(str, "\n", "<br>"); else str = replace(str, "<br>", "\n"); return str; } /** * replace, replace a string with another string in a string * * @param handleStr * @param pointStr * @param repStr * @return string, */ public static String replace(String handleStr, String pointStr, String repStr) { String str = new String(); int pos1, pos2; try { if (handleStr.length() > 0) { pos1 = handleStr.indexOf(pointStr); pos2 = 0; while (pos1 != -1) { str += handleStr.substring(pos2, pos1); str += repStr; pos2 = pos1 + pointStr.length(); pos1 = handleStr.indexOf(pointStr, pos2); } str += handleStr.substring(pos2); } } catch (Exception error) { error.printStackTrace(); } return str; } }