.replaceAll(/s/g,'')
name = name.strip()
//Extenion function
fun String.removeWhitespaces() = replace(" ", "")
// Uses
var str = "This is an example text".removeWhitespaces()
println(str)
$x = " abc ";
print(trim($x));
There are three versions of trim().
trim(): trims white space on both ends
rtrim(): trims white space on the right end
ltrim(): trims white space on the left end
Note that trim() does not remove white space in the middle of the string.