Here you can find the source of htmlEntityEncode(String s)
Parameter | Description |
---|---|
s | a parameter |
public static String htmlEntityEncode(String s)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w .j av a2 s. com*/ * Encodes given string with utf-8 encoding for html. * * @param s * @return */ public static String htmlEntityEncode(String s) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9') { buf.append(c); } else { buf.append("&#" + (int) c + ";"); /*if (c == '/' || c == '<' || c == '>' || c == ' ' || c == '\r' || c == '\n' || c == '"') { buf.append(c); } else { buf.append("&#" + (int) c + ";"); }*/ } } return buf.toString(); } }