onEachIndexed
Performs the given action on each character, providing sequential index with the character, and returns the char sequence itself afterwards.
inline fun <S : CharSequence> S.onEachIndexed(action: (index: Int, Char) -> Unit): S(source)
val text = "Kotlin"
text.onEachIndexed { index, char ->
println("Index $index: $char")
}
println("Original text: $text")