//用指定的字符替换字符串中某个字符
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,"<","<");
re=replace(re,">",">");
re=replace(re,"\n","<br>");
re=replace(re," "," ");
re=replace(re,"'","'");
return re;
}
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,"<","<");
re=replace(re,">",">");
re=replace(re,"\n","<br>");
re=replace(re," "," ");
re=replace(re,"'","'");
return re;
}
如果采用采用空格替代,那么还原时,就会出现问题.
如果采用空格代替单引号,则下面这个情况:
afdasdf'asdfasd asdfas'asdfas
将单引号换为空格,则读出来时就成
afdasdf'asdfasd'asdfas'asdfas
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();
}
}%>