我有一个开/关按钮,我想更改字符串的值,如果字符串包含randomnessOn
它将更改为randomnessOff
,反之亦然。我不能只覆盖字符串,因为它不仅包含开/关按钮的状态值。我试过这段代码。
if(command.equals(randFor) | command.equals(randBack) | command.equals(randButton)){
if(option.contains("randomnessOf")){
randomness = true;
randState = "ON";
randStateX = 975;
randStateY = 245;
option = option.replace("randomnesOff", "randomnessOn");
}
if(option.contains("randomnessOn")){
randomness = false;
randState = "OFF";
randStateX = 970;
randStateY = 245;
option = option.replace("randomnesOn", "randomnessOff");
}
loadOptions();
}
它将更改randState
字符串的文本并更改文本的位置,但不会替换option
字符串中的单词,那么我将如何替换字符串中的单词?