code: public String replace(Map<String, String> varMap)
     {
        StringBuilder newString = new StringBuilder();
  
        int p = 0;
        int p0 = 0;
        while (true)
        {
           p = templateText.indexOf("${", p);
           if (p == -1)
           {
              newString.append(templateText.substring(p0, templateText.length()));
              break;
           }
           else
           {
              newString.append(templateText.substring(p0, p));
           }
           p0 = p;
           p = templateText.indexOf("}", p);
           if (p != -1)
           {
              String varName = templateText.substring(p0 + 2, p).trim();
              if (varMap.containsKey(varName))
              {
                 newString.append(varMap.get(varName));
                 p0 = p + 1;
              }
           }
        }
        return newString.toString();
     }
docs: Replace string in the template text
  
  @param varMap variable map
  @return replaced string