Java の replace() メソッドの代替関数は何ですか? replace メソッドは古い文字を新しい文字に置き換えますが、私のコードはハングマンのようなもので、最初は _ _ _ _ があり、特定の charAt() を charAt(2) = ' のように置き換える代わりに replace() を使用すると、 A'、それはすべての _ を A に置き換えます。特定の文字を置き換えるための代替手段について何か提案はありますか? ありがとうございました
これが私のコードフラグメントです。
guessLetter = txtguesswordS.getText().toString();
char letter = guessLetter.charAt(0);
int indx = word.indexOf(letter);
public void convertUnderscore(String word){
for(int x = 0;x<word.length();x++){
Uscore += "-";
}
public void replaceLetter(char letter, int indx){
char oldLetter;
oldLetter = Uscore.charAt(indx);
update = Uscore.replace(oldLetter, letter);
}