forEachIndexed

Performs the given action on each character, providing sequential index with the character.

inline fun CharSequence.forEachIndexed(action: (index: Int, Char) -> Unit)(source)
val greeting = "Hello, Kotlin!"

greeting.forEachIndexed { index, char ->
    println("Character at index $index is '$char'")
}

Source