title: Groovy string interpolation when string is defined before the interpolated variables are defined
body: <p>I have a similar question to this:</p>
  
  <p><a href="https://stackoverflow.com/questions/28997518/groovy-string-interpolation-with-value-only-known-at-runtime/55422491#55422491">Groovy string interpolation with value only known at runtime</a></p>
  
  <p>What can be done to make the following work:</p>
  
  <pre><code>def message = 'Today is ${date}, your id is: ${id}';
  def date1 = '03/29/2019'
  def id1 = '12345'
  def result = {date, id -&gt; "${message}"}
  println(result(date1, id1))
  </code></pre>
  
  <p>So I want to take a string that has already been defined elsewhere (for simplicity I define it here as 'message'), having the interpolated ${date} and ${id} already embedded in it, and process it here using the closure, with definitions for the input fields.</p>
  
  <p>I've tried this with various changes, defining message in the closure without the "${}", using single or double quotes, embedding double quotes around the interpolated vars in the string 'message', etc., I always get this result:</p>
  
  <pre><code>Today is ${date}, your id is: ${id}
  </code></pre>
  
  <p>But I want it to say:</p>
  
  <pre><code>Today is 03/29/2019, your id is: 12345
  </code></pre>
  
  <p>The following worked but I am not sure if it is the best way:</p>
  
  <pre><code>def message = '"Today is ${date}, your id is: ${id}"'
  def sharedData = new Binding()                          
  def shell = new GroovyShell(sharedData)                 
  sharedData.setProperty('date', '03/29/2019')     
  sharedData.setProperty('id', '12345')
  println(shell.evaluate(message))
  </code></pre>
  
  <p><a href="http://docs.groovy-lang.org/latest/html/documentation/guide-integrating.html" rel="nofollow noreferrer">http://docs.groovy-lang.org/latest/html/documentation/guide-integrating.html</a></p>