一个方法,改改就可以用 //convertString method:change the special characters
public String convertString(String strProcessString,String strType){ int intIndex = 0;
char chrChar ;
StringBuffer sbString;
if (strProcessString == null || strProcessString.equals(""))
return "无";
sbString = new StringBuffer(strProcessString);
while (intIndex < sbString.length()) {
chrChar = sbString.charAt(intIndex); if(strType.equalsIgnoreCase("save") || strType.equalsIgnoreCase("search")){
if (chrChar == '\'') {
sbString.replace(intIndex, intIndex+1, "''");
intIndex += 2;
continue;
} if (chrChar == '"') {
sbString.replace(intIndex, intIndex+1, """);
intIndex += 5;
continue;
}
if(strType.equalsIgnoreCase("search")){
if (chrChar == '_') {
sbString.replace(intIndex, intIndex+1, "[_]");
intIndex += 3;
continue;
}
if (chrChar == '%') {
sbString.replace(intIndex, intIndex+1, "[%]");
intIndex += 3;
continue;
}
if (chrChar == '\\') {
sbString.replace(intIndex, intIndex+1, "[\\]");
intIndex += 3;
continue;
}
if (chrChar == '\'') {
sbString.replace(intIndex, intIndex+1, "\'\'");
intIndex += 4;
continue;
}
}
}
else if(strType.equalsIgnoreCase("body") || strType.equalsIgnoreCase("space")){ if (chrChar == '\n') {
sbString.replace(intIndex, intIndex+1, "<br>");
intIndex += 4;
continue;
}
if (chrChar == '<') {
sbString.replace(intIndex, intIndex+1, "<");
intIndex += 4;
continue;
}
if (chrChar == '>') {
sbString.replace(intIndex, intIndex+1, ">");
intIndex += 4;
continue;
}
if(strType.equalsIgnoreCase("space")){ if (chrChar == ' ') {
sbString.replace(intIndex, intIndex+1, " ");
intIndex += 5;
continue;
}
}
}
else if(strType.equalsIgnoreCase("text")){ if (chrChar == '"') {
sbString.replace(intIndex, intIndex+1, """);
intIndex += 5;
continue;
}
}
intIndex++;
}
return sbString.toString(); }
public String convertString(String strProcessString,String strType){ int intIndex = 0;
char chrChar ;
StringBuffer sbString;
if (strProcessString == null || strProcessString.equals(""))
return "无";
sbString = new StringBuffer(strProcessString);
while (intIndex < sbString.length()) {
chrChar = sbString.charAt(intIndex); if(strType.equalsIgnoreCase("save") || strType.equalsIgnoreCase("search")){
if (chrChar == '\'') {
sbString.replace(intIndex, intIndex+1, "''");
intIndex += 2;
continue;
} if (chrChar == '"') {
sbString.replace(intIndex, intIndex+1, """);
intIndex += 5;
continue;
}
if(strType.equalsIgnoreCase("search")){
if (chrChar == '_') {
sbString.replace(intIndex, intIndex+1, "[_]");
intIndex += 3;
continue;
}
if (chrChar == '%') {
sbString.replace(intIndex, intIndex+1, "[%]");
intIndex += 3;
continue;
}
if (chrChar == '\\') {
sbString.replace(intIndex, intIndex+1, "[\\]");
intIndex += 3;
continue;
}
if (chrChar == '\'') {
sbString.replace(intIndex, intIndex+1, "\'\'");
intIndex += 4;
continue;
}
}
}
else if(strType.equalsIgnoreCase("body") || strType.equalsIgnoreCase("space")){ if (chrChar == '\n') {
sbString.replace(intIndex, intIndex+1, "<br>");
intIndex += 4;
continue;
}
if (chrChar == '<') {
sbString.replace(intIndex, intIndex+1, "<");
intIndex += 4;
continue;
}
if (chrChar == '>') {
sbString.replace(intIndex, intIndex+1, ">");
intIndex += 4;
continue;
}
if(strType.equalsIgnoreCase("space")){ if (chrChar == ' ') {
sbString.replace(intIndex, intIndex+1, " ");
intIndex += 5;
continue;
}
}
}
else if(strType.equalsIgnoreCase("text")){ if (chrChar == '"') {
sbString.replace(intIndex, intIndex+1, """);
intIndex += 5;
continue;
}
}
intIndex++;
}
return sbString.toString(); }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货