You can use the template framework in Groovy, so this solves your problem:
String stringFromDatabase = 'Hello ${name}!' String name = 'world' def engine = new groovy.text.SimpleTemplateEngine() assert 'Hello world!'== engine.createTemplate(stringFromDatabase).make([name:name]).toString()
You can find documents here: http://docs.groovy-lang.org/latest/html/documentation/template-engines.html#_introduction
The GString class is abstract, and the implementation of the abstract GStringImpl class works on arrays of strings that it receives from the analysis phase along with the values.
Jacob Aae Mikkelsen
source share