jdk为1。3版本,没有replaceAll()方法
public class Trans {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
/**
*
* @param sourceString
* @param toReplaceString
* @param replaceString
* @return
*/
public static String transChar(String sourceString, String toReplaceString,
String replaceString) {
String returnString = sourceString;
int stringLength = 0;
if (toReplaceString != null) {
stringLength = toReplaceString.length();
}
if (returnString != null && returnString.length() > stringLength) {
int max = 0;
String S4 = "";
//int i = sourceString.length();
for (int i = 0; i < sourceString.length(); i++) {
max = i + toReplaceString.length() > sourceString.length() ? sourceString
.length()
: i + stringLength;
String S3 = sourceString.substring(i, max);
if (!S3.equals(toReplaceString)) {
S4 += S3.substring(0, 1);
} else {
S4 += replaceString;
i += stringLength - 1;
}
}
returnString = S4;
}
return returnString;
}
}