package com.utils;
/**
* HTML特殊字符转换类
*
* @version1.0 2007-10-30
* @author王世清
*/
public class ToHtml {
public static String toHtml(String str) {
if (str == null)
return null;
StringBuffer sb = new StringBuffer();
int len = str.length();
for (int i = 0; i < len; i++) {
char c = str.charAt(i);
switch (c) {
case ' ':
sb.append(" ");
break;
case '\n':
sb.append("<br>");
break;
case '\r':
break;
case '\'':
sb.append("'");
break;
case '<':
sb.append("<");
break;
case '>':
sb.append(">");
break;
case '&':
sb.append("&");
break;
case '"':
sb.append(""");
break;
case '\\':
sb.append("\");
break;
default:
sb.append(c);
}
}
return sb.toString();
}
}
posted on 2008-07-16 17:04
Crying 阅读(195)
评论(0) 编辑 收藏 所属分类:
Jsp+Struts