【Java开源代码栏目提醒】:网学会员为广大网友收集整理了,CAEncode.java,希望对大家有所帮助!
package mybbs;
import java.util.*;
public class CAEncode {
String re, re1;
public void CAEncode() {}
public String _conv(String n) {
byte[] temp;
try {
temp = n.getBytes("ISO-8859-1");
n = new String(temp, "GBK");
}
catch (Exception e) {}
return n;
}
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;
}
public String repItem(String mm) {
re1 = replace(mm, "<", "<");
re1 = replace(re1, ">", ">");
re1 = replace(re1, "\n", "#");
re1 = replace(re1, " ", " ");
re1 = replace(re1, "'", "'");
return re1;
}
public String htmlEncode(String s){
re = replace(s, "<", "<");
re = replace(re, ">", ">");
re = replace(re, "\n", "<br>");
re = replace(re, " ", " ");
re = replace(re, "'", "'");
return re;
}
public String OutRep(String s){
re = replace(s, "<", "<");
re = replace(re, ">", ">");
re = replace(re, "\n", "<br>");
re = replace(re, " ", " ");
re = replace(re, "'", "'");
return re;
}
}