关闭

用文本框输入内容,显示时,识别回车换行空格的函数

标签: stringnull
1484人阅读 评论(0) 收藏 举报
分类:


<%! 
   String  change(String  String1) 
       { 
               if(  String1  ==  null  ) 
                       return  ""; 
               else 
               { 
                       int  int2  =  String1.length(); 
                       StringBuffer  StringBuffer3  =  new  StringBuffer(); 
                       int  int4; 
 
                       for(  int4  =  0;  int4  <  int2;  ++int4  ) 
                       { 
                               char  char5  =  String1.charAt(  int4  ); 
 
                               switch(  char5  ) 
                               { 
                                       case  62: 
                                               StringBuffer3.append(  "&gt;"  ); 
                                               break; 
                                       case  60: 
                                               StringBuffer3.append(  "&lt;"  ); 
                                               break; 
                                       case  38: 
                                               StringBuffer3.append(  "&amp;"  ); 
                                               break; 
                                       case  32: 
                                               StringBuffer3.append(  "&nbsp;"  ); 
                                               break; 
                                       case  10: 
                                               StringBuffer3.append(  "<BR>"  ); 
                                               break; 
                                       default: 
                                               StringBuffer3.append(  char5  ); 
                                               break; 
                                       case  13: 
                                               break; 
                               } 
                       } 
                       return  StringBuffer3.toString(); 
               } 
       } 
 
%>
----------------------

原来做的系统是输入时把回车换行等转换一下,但在修改的时候又不知道如何把代码再转换回来了,所以想了一个办法是,在用文本框输入和修改内容的时候都不做转换,只在显示内容的时候用这个函数,转换一下就OK了。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:108681次
    • 积分:2155
    • 等级:
    • 排名:第17590名
    • 原创:104篇
    • 转载:20篇
    • 译文:0篇
    • 评论:8条
    文章分类
    最新评论