public static String removeStr(String src, String str) {
if (src == null || str == null) return src;
int idx = src.indexOf(str);
if (idx == -1) return src;
int pst = 0;
char[] cs = src.toCharArray();
char[] rs = new char[src.length() - str.length()];
for (int i = 0; i < cs.length; i ++) {
if (i >= idx && i < idx + str.length()) continue;
rs[pst] = cs[i];
pst ++;
}
return new String(rs);
}
public static String replaceStr(String src, String target, String replacement) {
if (src == null || target == null || replacement == null) return src;
int idx = src.indexOf(target);
if (idx == -1) return src;
int pst = 0;
char[] cs = src.toCharArray();
char[] rs = new char[src.length() - target.length() + replacement.length()];
for (int i = 0; i < cs.length; i ++) {
if (i == idx) {
for (char c : replacement.toCharArray()) {
rs[pst] = c;
pst ++;
}
continue;
}
if (i > idx && i < idx + target.length()) continue;
rs[pst] = cs[i];
pst ++;
}
return new String(rs);
}
/**
*
* @param src
* @param target
* @param replacement
* @return
*/
public static String replaceAllStr(String src, String target, String replacement) {
if (src == null || target == null || replacement == null) return src;
int idx = src.indexOf(target);
if (idx == -1) return src;
int pst = 0;
char[] cs = src.toCharArray();
char[] rs = new char[src.length() - target.length() + replacement.length()];
for (int i = 0; i < cs.length; i ++) {
if (i == idx) {
for (char c : replacement.toCharArray()) {
rs[pst] = c;
pst ++;
}
continue;
}
if (i > idx && i < idx + target.length()) continue;
rs[pst] = cs[i];
pst ++;
}
return replaceAllStr(new String(rs), target, replacement);
}