I am trying to ignore case sensitivity on a string. For example, a user can put "Brazil" or "brasil" and the fun will trigger. How do I implement this? I am new to Kotlin.
fun questionFour() {
val edittextCountry = findViewById<EditText>(R.id.editTextCountry)
val answerEditText = edittextCountry.getText().toString()
if (answerEditText == "Brazil") {
correctAnswers++
}
if (answerEditText == "Brasil") {
correctAnswers++
}
}
EDIT
Another person helped me write like this. My question now about this way is "Is there a cleaner way to write this?"
fun questionFour() {
val edittextCountry = findViewById<EditText>(R.id.editTextCountry)
val answerEditText = edittextCountry.getText().toString()
if (answerEditText.toLowerCase() == "Brazil".toLowerCase() || answerEditText.toLowerCase() == "Brasil".toLowerCase()) {
correctAnswers++
}
}
Answer
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++
}
}