src/main/java/org/jboss/util/Strings.java
/**
    * 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.
Substitute sub - strings in side of a string .
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)
      {
         buff.append(string.substring(begin, range.begin));
         String key = string.substring(range.begin + beginToken.length(),
            range.end);
         Object value = map.get(key);
         if (value == null) value = EMPTY;
         buff.append(value);
         begin = range.end + endToken.length();
         rangeEnd = begin;
      }
      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 ) { buff . append ( string . substring ( begin , range . begin ) ) ; String key = string . substring ( range . begin + beginToken . length ( ) , range . end ) ; Object value = map . get ( key ) ; if ( value == null ) value = EMPTY ; buff . append ( value ) ; begin = range . end + endToken . length ( ) ; rangeEnd = begin ; } buff . append ( string . substring ( begin , string . length ( ) ) ) ; return buff . toString ( ) ; }
Substitute sub-strings in side of a string.
Substitute sub - strings in side of a string .
// append the first part of the string // Get the string to replace from the map // if mapping does not exist then use empty; // append the replaced string // update positions // append the rest of the string