Skip to content

Instantly share code, notes, and snippets.

@ajaypro
Created June 13, 2020 16:32
Show Gist options
  • Save ajaypro/d82b74dcd1848a1610efca55533c6af5 to your computer and use it in GitHub Desktop.
Save ajaypro/d82b74dcd1848a1610efca55533c6af5 to your computer and use it in GitHub Desktop.
// replace whitespaces in string
fun main() {
var str = "T his is b ett er."
var pharse = str.replace("\\s".toRegex(),"")
println(pharse)
}
We've used regular expression \\s that finds all white space characters (tabs, spaces, new line character, etc.)
in the string. Then, we replace it with "" (empty string literal).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment