Skip to content

Instantly share code, notes, and snippets.

@acatejr
Last active August 29, 2015 14:05
Show Gist options
  • Save acatejr/3c0afe17d78610059366 to your computer and use it in GitHub Desktop.
Save acatejr/3c0afe17d78610059366 to your computer and use it in GitHub Desktop.
Groovy string cleanup.
/**
* Clean spaces and extraneous characters from a text string.
*
* @params source The source string.
*
* @return The cleaned version of the input string.
*
*/
static def cleanString(String source) {
if ( source && source.length() > 0 ) {
def wordList = source.split("\\s+")
[",", ""].each() { i ->
wordList -= i
}
wordList.join(" ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment