Skip to content

Instantly share code, notes, and snippets.

@hamishdickson
Created January 2, 2015 15:52
Show Gist options
  • Select an option

  • Save hamishdickson/3f1dfbd2ff4ffebe6f7b to your computer and use it in GitHub Desktop.

Select an option

Save hamishdickson/3f1dfbd2ff4ffebe6f7b to your computer and use it in GitHub Desktop.
Map loop
def newInstallFile = []
String oldline = "hamish blah blah hungry"
def MAP = ["hamish" : "greg", "blah" : "smash", "foo" : "bar"]
MAP.each { m ->
newLine = oldline.replaceAll(m.key.toString(), m.value.toString())
newInstallFile << newLine
}
print newInstallFile
// this prints: [greg blah blah hungry, hamish smash smash hungry, hamish blah blah hungry]
String newInstallFile = ""
String oldline = "hamish blah blah hungry"
def MAP = ["hamish" : "greg", "blah" : "smash", "foo" : "bar"]
MAP.each { m ->
newLine = oldline.replaceAll(m.key.toString(), m.value.toString())
newInstallFile += "\n" + newLine
}
print newInstallFile
/*
prints
greg blah blah hungry
hamish smash smash hungry
hamish blah blah hungry
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment