//用指定的字符替换字符串中某个字符
public String replace(String con,String tag,String rep){
int j=0;
int i=0;
int k=0;
String RETU="";
String temp=con;
int tagc=tag.length();
while(i<con.length()){
if(con.substring(i).startsWith(tag)){
temp=con.substring(j,i)+rep;
RETU+=temp;
i+=tagc;
j=i;
}
else{i+=1;
}
}
RETU+=con.substring(j);
return RETU;
}//禁用HTML代码编码
public String html(String s){
String re;
re=replace(s,"<","&lt;");
    re=replace(re,">","&gt;");
    re=replace(re,"\n","<br>");
    re=replace(re," ","&nbsp;");
    re=replace(re,"'","&#39");
    return re;
}

解决方案 »

  1.   

    我不清楚用什么替代较好!
    如果采用采用空格替代,那么还原时,就会出现问题.
    如果采用空格代替单引号,则下面这个情况:
    afdasdf'asdfasd asdfas'asdfas
    将单引号换为空格,则读出来时就成
    afdasdf'asdfasd'asdfas'asdfas
      

  2.   

    <%!
     String toStandardString(String Stringtemp)
       {
            if( Stringtemp == null || Stringtemp.length() == 0 )
                return "";
            else
            {
                int Stringlength = Stringtemp.length();
                StringBuffer StringBuffertemp = new StringBuffer();
                int count;            for( count = 0; count < Stringlength; ++ count )
                {
                    char chartemp = Stringtemp.charAt( count );                if( chartemp == 39 )
                        StringBuffertemp.append("'"+chartemp);
                    else
                        StringBuffertemp.append( chartemp );
                }
                return StringBuffertemp.toString();
            }
        }%>
      

  3.   

    用 zijianyi(紫剑伊) 的;通吃:)
      

  4.   

    http://www.csdn.net/expert/topic/791/791072.xml?temp=.2182428
      

  5.   

    Czh_cz(风清云淡) ::)你试试看 :)