文本区域 换符号

public static String Replace(String str_source,String str_original,String str_new) {

   if(str_source == null) 

    return null;

   StringBuffer output = new StringBuffer();

   int lengOfsource = str_source.length();

   int lengOfold = str_original.length();

   int posStart = 0;

   int pos;

   while((pos = str_source.indexOf(str_original,posStart)) >= 0) {

     output.append(str_source.substring(posStart,pos));

     output.append(str_new);

     posStart = pos + lengOfold;

   }

   if(posStart < lengOfsource) {

     output.append(str_source.substring(posStart));

   }

   return output.toString();

 }

 

public static String toHtml(String s) 

{

   s = Replace(s,"<","&lt;");

   s = Replace(s,">","&gt;");

   s = Replace(s,"&","&amp;");

   s = Replace(s,"/t","    ");

   s = Replace(s,"/r/n","/n");

   s = Replace(s,"/n","<br />");

   s = Replace(s,"  "," &nbsp;");

   s = Replace(s,"'","&#39;");

   s = Replace(s,"//","&#92;");

   return s;

}

public static String unHtml(String s)

{

s = Replace(s,"&nbsp;"," ");

s = Replace(s,"<br>","/n");

return s;

}

 

使用如下:

<textarea rows="6" cols="45" id="content" >we have a long way to go</textarea>

 

toHtml("we have a long way to go");

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值