code: public static String subst(final StringBuffer buff, final String string,
              final String replace[], final char token)
     {
        int i = string.length();
        for (int j = 0; j >= 0 && j < i; j++)
        {
           char c = string.charAt(j);
  
           // if the char is the token, then get the index
           if (c == token)
           {
  
              // if we aren't at the end of the string, get the index
              if (j != i)
              {
                 int k = Character.digit(string.charAt(j + 1), 10);
  
                 if (k == -1)
                 {
                    buff.append(string.charAt(j + 1));
                 }
                 else if (k < replace.length)
                 {
                    buff.append(replace[k]);
                 }
  
                 j++;
              }
           }
           else
           {
              buff.append(c);
           }
        }
  
        return buff.toString();
     }
docs: Substitute index identifiers with the replacement value from the given array for the corresponding index.
  
  @param buff The string buffer used for the substitution (buffer is not reset).
  @param string String substitution format.
  @param replace Array of strings whose values will be used as replacements in the given string when a token with
  their index is found.
  @param token The character token to specify the start of an index reference.
  @return Substituted string.