title: How to use String.format in groovy?
body: <p>The code below prints the <code>response</code> variable preceded by spaces.</p>
  
  <p>The number of spaces to be printed before the <code>response</code> variable is equivalent to the difference of the <code>itemNumber</code> and the <code>examineeResponses</code>.</p>
  
  <p>Now, is it possible to pad the string with zero (<code>"0"</code>) instead of spaces using String.format?</p>
  
  <pre><code>def converted = examineeResponses+String.format("%${itemNumber - 1}s", response)
  </code></pre>
  
  <p>Example using the above codes:</p>
  
  <pre><code>examineeResponses = '1' // String
  itemNumber = 10 //int
  response = '3' // String
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>"        3"
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>"000000003"
  </code></pre>