public static String format ( final String value , String ... params ) { validate ( value , NULL_STRING_PREDICATE , NULL_STRING_MSG_SUPPLIER ) ; Pattern p = Pattern . compile ( "\\{(\\w+)}" ) ; Matcher m = p . matcher ( value ) ; String result = value ; while ( m . find ( ) ) { int paramNumber = Integer . parseInt ( m . group ( 1 ) ) ; if ( params == null || paramNumber >= params . length ) { throw new IllegalArgumentException ( "params does not have value for " + m . group ( ) ) ; } result = result . replace ( m . group ( ) , params [ paramNumber ] ) ; } return result ; }
Formats a string using parameters