The trim() Function is used to remove any leading and trailing whitespace from the String.
fun main() { var x = " Hello " var y = x.trim() println(y) }
In the above code, we have declared a String ' Hello ' with leading and trailing spaces.
Then we have used the 'trim()' function to remove any unwanted spaces from beginning and end.
Unwanted spaces are stripped out of it.