如题.可以用正则表达式的group搞,这里直接替换.
2.代码.
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { public static void main(String[] args) { String[] params = new String[] { "11","22","33","44" }; String templateString = "aaaa##bbbb##CCC##dddd##"; for (int i = 0; i < params.length; i++) { templateString = templateString.replaceFirst("##",params[i]); } System.out.println("结果:" + templateString); } }原文链接:https://www.f2er.com/regex/361211.html