String Trim in Kotlin

Level 270 keystrokes

Removes leading and trailing whitespace from a string with trim().

Kotlin code

// Two spaces at each end; the total length is 15
1val text = " hello world "
// trim() returns a new string without the outer whitespace: hello world
2println(text.trim())
// text itself is unchanged, so its length is still 15
3println(text.length)

Output

hello world
15
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Kotlin code and how often they appear.

  • (× 3
  • )× 3
  • .× 2
  • "× 2
  • =× 1

More Kotlin examples at level 2

← Kotlin typing practice