I'm currently facing a variable substitution related problem in groovy. While this is quite trivial:
Map map = [s1:"Hello", s2:"World"]
println "${map.s1} ${map.s2}!" // "Hello World!"
As this works, I'm pretty sure that something like this should work as well:
Map map = [s1:"Hello", s2:"World"]
def dynamic = loadStringFromFile();
println "${dynamic} ${dynamic.class}" // "${s1} ${s2}! (java.lang.String)"
// now the voodoo part
println applyVoodoo(dynamic, map) // "Hello World!"
Does anybody know how to get this working?
Cheers
You would normally do this with Groovy Templates.
dynamic.replaceAll(/\$\{(\w+)\}/) { m, k -> map[k] }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With