我正在使用这段代码:
start = str.indexOf('<');
finish = str.indexOf('>');
between = str.substring(start + 1, finish);
replacement = str.substring(start, finish + 1);
System.out.println(between + " " + replacement); //for debug purposes
forreplacement = JOptionPane.showInputDialog(null, "Enter a " + between);
System.out.println(forreplacement); //for debug purposes
counter = counter - 1;
其中“str”是正在使用的字符串。如何用字符串 str 中的字符串“forreplacement”(在弹出框中输入的内容)替换子字符串“replacement”?