Using " contains " in kotlin for provide if the input have contains english letters

Viewed 44

how can I use " contains "? if the input have contains english letters it's always shows me false even if am write a english letter small/capital

 val eLang: String = ("aA b   B c   C d   D e   E f   F g   G h   H i   I j   J k   K l   L m   M n   N o   O p   P q   Q r   R s   S t   T u   U v   V w   W x   X y   Y z   Z")


   

output : false

       println( input_string?.contains(eLang, ignoreCase = true))

main code

class Loop {

    public val input_string: String? = readLine().toString()
    public val input_size = readLine()?.toInt()

    fun looping(a: String, b: Int) {
        val eLang: String = ("aA b   B c   C d   D e   E f   F g   G h   H i   I j   J k   K l   L m   M n   N o   O p   P q   Q r   R s   S t   T u   U v   V w   W x   X y   Y z   Z")
        if ((input_size!! > 1) && input_string != "") {
            for (i in 0 until input_size) {

                println(input_string)
            }

            input_string?.let { println("length word you type : ${it.length}") }
            input_size?.let { println("Count looping: ${(input_size)}") }

           println( input_string?.contains(eLang, ignoreCase = true))



        }
    }

}
1 Answers

If you want to test if an input has any letters, simply do

val hasALetter = input.any(Char::isLetter)

What you're doing is checking if the input has the entire alphabet string, which is not what you want to be doing.

Related