/**
* @param str:要插入的字符串
* @param keyword:在那个字符插入
* @param before:在字符前需要插入的字段
*/
public static String replacementInfo(String str, String keyword, String before) {
StringBuilder sb = new StringBuilder(str);
String rs = str;
try {
//字符第一次出现的位置
int index = sb.indexOf(keyword);
while (index != -1) {
sb.insert(index, before);
//下一次出现的位置,
index = sb.indexOf(keyword, index + before.length() + 1);
}
rs = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
return rs;
}
10-24
669
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-06
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交