我有我的控制台(下图),我有一个命令将所有 oldstinrg 替换为 newstring。但是我如何计算其中有多少被替换了?
(如果代码仅将 a 替换为 b 一次,则为 1,但如果将 a 替换为 b 两次,则值为 2)
(这只是代码的一部分,但不需要其他部分或与这部分代码有任何关系)
else if(intext.startsWith("replace ")){
String[] replist = original.split(" +");
String repfrom = replist[1];
String repto = replist[2];
lastorep = repfrom;
lasttorep = repto;
String outtext = output.getText();
String newtext = outtext.replace(repfrom, repto);
output.setText(newtext);
int totalreplaced = 0; //how to get how many replaced strings were there?
message("Total replaced: " + totalreplaced + " from " + repfrom + " to " + repto);
}