找到某个单词后,在另一个单词之前添加单词

时间:2020-07-07 01:16:17

标签: java

我想在字符串的每个“ from”前面添加“ count(*)”。

给出:Select thing1, thing2 from table;

输出:Select thing1, thing2, count (*) from table;

我尝试了这个,但是没有用:

String a = “ Select thing1, thing2 from table;”

String[] b = “form”.split(“\\s”)

For(string string: b){
If(a.contains(form)


}

1 个答案:

答案 0 :(得分:1)

尝试一下:

int idx = a.indexOf("from");
System.out.println(a.substring(0, idx-1) + ", count(*) " + a.substring(idx));

输出:

Select thing1, thing2, count(*) from table;