public static String sprintf ( String s , Object [ ] params ) { if ( ( s == null ) || ( params == null ) ) { return s ; } StringBuffer result = new StringBuffer ( "" ) ; String [ ] ss = split ( s ) ; int p = 0 ; for ( int i = 0 ; i < ss . length ; i ++ ) { char c = ss [ i ] . charAt ( 0 ) ; String t = ss [ i ] . substring ( 1 ) ; if ( c == ' ' ) { result . append ( t ) ; } else { Object param = params [ p ] ; if ( param instanceof Integer ) { result . append ( new Format ( t ) . form ( ( Integer ) param ) ) ; } else if ( param instanceof Long ) { result . append ( new Format ( t ) . form ( ( Long ) param ) ) ; } else if ( param instanceof Character ) { result . append ( new Format ( t ) . form ( ( Character ) param ) ) ; } else if ( param instanceof Double ) { result . append ( new Format ( t ) . form ( ( Double ) param ) ) ; } else if ( param instanceof Double ) { result . append ( new Format ( t ) . form ( new Float ( ( Double ) param ) ) ) ; } else { result . append ( new Format ( t ) . form ( param . toString ( ) ) ) ; } p ++ ; } } return result . toString ( ) ; }
Sprintf multiple strings .