public static String toHTMLString(String in) {
StringBuffer out = new StringBuffer();
for (int i = 0; in != null && i < in.length(); i++) {
char c = in.charAt(i);
if (c == '\'')
out.append("'");
else if (c == '\"')
out.append(""");
else if (c == '<')
out.append("<");
else if (c == '>')
out.append(">");
else if (c == '&')
out.append("&");
else if (c == ' ')
out.append(" ");
else if (c == '\n')
out.append("<br>");
else
out.append(c);
}
return out.toString();
}
StringBuffer out = new StringBuffer();
for (int i = 0; in != null && i < in.length(); i++) {
char c = in.charAt(i);
if (c == '\'')
out.append("'");
else if (c == '\"')
out.append(""");
else if (c == '<')
out.append("<");
else if (c == '>')
out.append(">");
else if (c == '&')
out.append("&");
else if (c == ' ')
out.append(" ");
else if (c == '\n')
out.append("<br>");
else
out.append(c);
}
return out.toString();
}
可惜我忘了是什么标记了..你随便查一下就ok了...
这样你的文字里的空格,回车之类的,html会完全按原来显示...
那么只要转换一下,
把\n转换成<br>就可以了。
自己写一个字符的转换方法先。