Func.jsp
上传用户:huijianzhu
上传日期:2009-11-25
资源大小:9825k
文件大小:1k
- <%!
- public static String toHtml(String s) {
- s = Replace(s,"&","&");
- s = Replace(s,"<","<");
- s = Replace(s,">",">");
- s = Replace(s,"t"," ");
- s = Replace(s,"rn","n");
- s = Replace(s,"n","<br>");
- s = Replace(s," "," ");
- s = Replace(s,"'","'");
- s = Replace(s,"\","\");
- return s;
- }
- //字符串本身有replace函数。
- public static String Replace(String source,String oldString,String newString) {
- if(source == null) return null;
- StringBuffer output = new StringBuffer();
- int lengOfsource = source.length();
- int lengOfold = oldString.length();
- int posStart = 0;
- int pos;
- while((pos = source.indexOf(oldString,posStart)) >= 0) {
- output.append(source.substring(posStart,pos));
- output.append(newString);
- posStart = pos + lengOfold;
- }
- if(posStart < lengOfsource) {
- output.append(source.substring(posStart));
- }
- return output.toString();
- }
- public static String toEnHtml(String s) {
- s = Replace(s,"&","&");
- s = Replace(s,"<","<");
- s = Replace(s,">",">");
- s = Replace(s," ","t");
- s = Replace(s,"n","rn");
- s = Replace(s,"<br>","n");
- s = Replace(s," "," ");
- s = Replace(s,"'","'");
- s = Replace(s,"\","\");
- return s;
- }
- %>