好了,你可以编写一个循环:
public static void replaceAll(StringBuilder builder, String from, String to){ int index = builder.indexOf(from); while (index != -1) { builder.replace(index, index + from.length(), to); index += to.length(); // Move to the end of the replacement index = builder.indexOf(from, index); }}请注意,在某些情况下
lastIndexOf,从背面开始使用可能会更快。我怀疑是用短字符串替换长字符串的情况-因此,当你开始时,任何替换都很少复制。无论如何,这应该给你一个起点。



