Groovy: remove spaces from a string
Remove all the spaces from a string. It is like trim, trim-left, and trim-right together.
examples/groovy/remove_spaces.gvy
def input_text = " hello world " clean_text = input_text.replaceAll("\\s","") println("'${input_text}'") // ' hello world ' println("'${clean_text}'") // 'helloworld'
$ groovy remove_spaces.gvy ' hello world ' 'helloworld'
Without the need to doubl-escape using ~//
examples/groovy/remove_spaces_no_escape.gvy
def input_text = " hello world " clean_text = input_text.replaceAll(~/\s/,"") println("'${input_text}'") // ' hello world ' println("'${clean_text}'") // 'helloworld'
groovy remove_spaces_no_escape.gvy
Published on 2018-10-30
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post