posts - 165, comments - 198, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

wap 文本展现 简单替换

Posted on 2008-06-04 17:19 G_G 阅读(229) 评论(0)  编辑  收藏 所属分类: javaGeneral


     public   static  String filter(String input) {
        
if  (input  ==   null ) {
            
return   null ;
        }
        StringReader stringReader 
=   new  StringReader(input);
        BufferedReader reader 
=   new  BufferedReader(stringReader);

        StringBuffer ret 
=   new  StringBuffer(input.length()  +   200 ); //  add more room to the result String

        String line 
=   null ;
        
try  {
            //换行后添加<br/>
            
while  ((line  =  reader.readLine())  !=   null ) {
                //wap 对 <  >的替换
                ret.append(line.replaceAll(
" < " " &lt; " ).replaceAll( " > " " &gt; " ). replaceAll( "&""&amp;" ) ).append( " <br/>&nbsp;&nbsp; " );
            }
// while
            
// 如果是最后一行
        }  catch  (IOException ex) {}

       
return   " &nbsp;&nbsp; " + ret.toString() ;

    }

    


只有注册用户登录后才能发表评论。


网站导航: