The stripTrailing() Function is used to remove any unwanted character from the right side of the String with Space by default.
fun main() {
var x = " Hello "
var y = x.stripTrailing()
println(y+"World")
}
In the above code, we have declared a String ' Hello ' with leading and trailing spaces.
-Function1.png)
Then we have used the 'stripTrailing()' function to remove the unwanted spaces from right side only.
-Function2.png)
So, the unwanted spaces are stripped out from the right side of the String.