How to remove leading and trailing whitespaces from a string in Kotlin

1 Answer

0 votes
fun main() {
    var s = "         kotlin python java php c c++    "

    println(s.length) // Length before trimming

    s = s.trim()

    println(s.length) // Length after trimming

    println(s) 
}


 
  
/*
run:
 
41
28
kotlin python java php c c++

*/

 



answered Jul 26 by avibootz
...