// 用以在显示时将某些字符转换为 HTML 符号(但并不改变字符本身,只改变显示方式)
public static String strToHTML(String str) {
StringBuffer sb = new StringBuffer();
int total = str.length();
char c = 'a'; for(int i=0;i<total;i++) {
c = str.charAt(i);
if(c==' ') { sb.append(" "); }
else if(c=='<') { sb.append("<"); }
else if(c=='>') { sb.append(">"); }
else if(c=='\n') { sb.append("<br>"); }
else { sb.append(c); }
} return sb.toString();
}
public static String strToHTML(String str) {
StringBuffer sb = new StringBuffer();
int total = str.length();
char c = 'a'; for(int i=0;i<total;i++) {
c = str.charAt(i);
if(c==' ') { sb.append(" "); }
else if(c=='<') { sb.append("<"); }
else if(c=='>') { sb.append(">"); }
else if(c=='\n') { sb.append("<br>"); }
else { sb.append(c); }
} return sb.toString();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货