我试图忽略字符串的区分大小写.例如,用户可以放置"巴西"或"巴西",乐趣将触发.我该如何实现?我是Kotlin的新手.
fun questionFour() {
val edittextCountry = findViewById<EditText>(R.id.editTextCountry)
val answerEditText = edittextCountry.getText().toString()
if (answerEditText == "Brazil") {
correctAnswers++
}
if (answerEditText == "Brasil") {
correctAnswers++
}
}
Run Code Online (Sandbox Code Playgroud)
另一个人帮我写这样的.我现在关于这种方式的问题是"有更简洁的方式来写这个吗?"
fun questionFour() {
val edittextCountry = findViewById<EditText>(R.id.editTextCountry)
val answerEditText = edittextCountry.getText().toString()
if (answerEditText.toLowerCase() == "Brazil".toLowerCase() || answerEditText.toLowerCase() == "Brasil".toLowerCase()) {
correctAnswers++
}
}
Run Code Online (Sandbox Code Playgroud)
fun questionFour() {
val edittextCountry = findViewById<EditText>(R.id.editTextCountry)
val answerEditText = edittextCountry.getText().toString()
if (answerEditText.equals("brasil", ignoreCase = true) || answerEditText.equals("brazil", ignoreCase = true)) {
correctAnswers++
}
}
Run Code Online (Sandbox Code Playgroud)