如何检查单词中的字母[hang子手]

时间:2019-09-27 15:22:51

标签: android kotlin

我希望我的按钮可以检查字母是否在单词中

word: Hai
user pres btnA
result : _a_
user pres btnH
result : Ha_

这就是我在Kotlin Android Studio所做的

 fun guessTry(click : View){
        val guessW = txtKata.toString()
        txtKata.text = null
        if (click == btnA){
            val a = btnA.text
            if(a in secretWord.toLowerCase() || a in secretWord.toUpperCase() ){
                corecGuess.add(guessW)
                wordSecret()
            }
        }
}
word: Hai
user pres btnA
result : _a_
user pres btnH
result : Ha_

1 个答案:

答案 0 :(得分:0)

我认为您可以尝试像这样更改if函数

fun guessTry(click : View){
        val guessW = txtKata.toString()
        txtKata.text = null
        if (click == btnA){
            val a = btnA.text
            if(secretWord.toLowerCase().contains(a) || secretWord.toUpperCase().contains(a)  ){
                corecGuess.add(guessW)
                wordSecret()
            }
        }
}