src/main/java/org/jboss/util/Strings.java
public static String subst(final StringBuffer buff, final String string,
      final Map map, final String beginToken,
      final String endToken)
   {
      int begin = 0, rangeEnd = 0;
      Range range;

      while ((range = rangeOf(beginToken, endToken, string, rangeEnd)) != null)
      {
         // append the first part of the string
         buff.append(string.substring(begin, range.begin));

         // Get the string to replace from the map
         String key = string.substring(range.begin + beginToken.length(),
            range.end);
         Object value = map.get(key);
         // if mapping does not exist then use empty;
         if (value == null) value = EMPTY;

         // append the replaced string
         buff.append(value);

         // update positions
         begin = range.end + endToken.length();
         rangeEnd = begin;
      }

      // append the rest of the string
      buff.append(string.substring(begin, string.length()));

      return buff.toString();
   }
public static String subst(final StringBuffer buff, final String string,
      final Map map, final String beginToken,
      final String endToken)
   {
      int begin = 0, rangeEnd = 0;
      Range range;

      while ((range = rangeOf(beginToken, endToken, string, rangeEnd)) != null)
      {
         // append the first part of the string
         buff.append(string.substring(begin, range.begin));

         // Get the string to replace from the map
         String key = string.substring(range.begin + beginToken.length(),
            range.end);
         Object value = map.get(key);
         // if mapping does not exist then use empty;
         if (value == null) value = EMPTY;

         // append the replaced string
         buff.append(value);

         // update positions
         begin = range.end + endToken.length();
         rangeEnd = begin;
      }

      // append the rest of the string
      buff.append(string.substring(begin, string.length()));

      return buff.toString();
   }
public static String subst ( final StringBuffer buff , final String string , final Map map , final String beginToken , final String endToken ) { int begin = 0 , rangeEnd = 0 ; Range range ; while ( ( range = rangeOf ( beginToken , endToken , string , rangeEnd ) ) != null ) { // append the first part of the string buff . append ( string . substring ( begin , range . begin ) ) ; // Get the string to replace from the map String key = string . substring ( range . begin + beginToken . length ( ) , range . end ) ; Object value = map . get ( key ) ; // if mapping does not exist then use empty; if ( value == null ) value = EMPTY ; // append the replaced string buff . append ( value ) ; // update positions begin = range . end + endToken . length ( ) ; rangeEnd = begin ; } // append the rest of the string buff . append ( string . substring ( begin , string . length ( ) ) ) ; return buff . toString ( ) ; }
Substitute sub-strings in side of a string.

@param buff       String buffer to use for substitution (buffer is not reset)
@param string     String to subst mappings in
@param map        Map of from->to strings
@param beginToken Beginning token
@param endToken   Ending token
@return           Substituted string
Substitute sub - strings in side of a string .