public class test {
public static String stringReplace(String str, String oldStr, String newStr) {
String returnStr = "";
int i, j, t, m, n;
n = 0;
j = oldStr.length();
if (str.indexOf(oldStr) > -1) {
while (str.indexOf(oldStr, n) > -1) {
i = str.length();
if (str.indexOf(oldStr) == 0) {
str = newStr + str.substring(j, i);
} else {
t = str.indexOf(oldStr);
m = t + j;
str = str.substring(0, t) + newStr + str.substring(m, i);
n = t + newStr.length() - j + 1;
}
}
}
returnStr = str;
return returnStr;
}
public static void main(String[] args) {
String str="";
str=stringReplace(str,"<","<");
str=stringReplace(str,">",">");
System.out.println(str);
}
}
编辑特别推荐: