Created
January 2, 2015 15:52
-
-
Save hamishdickson/3f1dfbd2ff4ffebe6f7b to your computer and use it in GitHub Desktop.
Map loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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