How to get first letter of each word in a string with Kotlin

1 Answer

0 votes
fun main() {
    val s = "kotlin python c++ java rust"
    
    for (word in s.split(" ")) {
        println(word[0])
    }
}


 
/*
run:
 
k
p
c
j
r
 
*/

 



answered Nov 1, 2024 by avibootz
...