public Scriptable printf(final String cFormat,final String[] args){
  final StringBuilder buf=new StringBuilder();
  final char PERCENT='%';
  int tokenCount=0;
  int stringLoct=0;
  int tokenPos=cFormat.indexOf(PERCENT);
  String obj;
  while (tokenPos != -1) {
    buf.append(cFormat.substring(stringLoct,tokenPos));
    int end2Pos;
    final char[] endTokens={'d','f','s','x'};
    int c=0;
    stringLoct=cFormat.indexOf(endTokens[c++],tokenPos);
    for (; c < endTokens.length; c++) {
      end2Pos=cFormat.indexOf(endTokens[c],tokenPos);
      if (stringLoct == -1 || (end2Pos != -1 && end2Pos < stringLoct)) {
        stringLoct=end2Pos;
      }
    }
    stringLoct++;
    final String tok=cFormat.substring(tokenPos,stringLoct);
    obj=args[tokenCount++];
    final int comma=obj.indexOf(',');
    final int stop=obj.indexOf('.');
    if ((comma != -1 && stop != -1) && (comma < stop)) {
      final StringBuilder str=new StringBuilder();
      char next;
      for (int i=0; i < obj.length(); i++) {
        next=obj.charAt(i);
        if (next != ',') {
          str.append(next);
        }
      }
      obj=str.toString();
    }
    final String val=convertToken(tok,obj);
    buf.append(val);
    tokenPos=cFormat.indexOf(PERCENT,tokenPos + 1);
  }
  if (stringLoct < cFormat.length()) {
    buf.append(cFormat.substring(stringLoct));
  }
  return context.newObject(scope,"String",new Object[]{buf.toString()});
}

public Scriptable printf ( final String cFormat , final String [ ] args ) { final StringBuilder buf = new StringBuilder ( ) ; final char PERCENT = '%' ; int tokenCount = 0 ; int stringLoct = 0 ; int tokenPos = cFormat . indexOf ( PERCENT ) ; String obj ; while ( tokenPos != - 1 ) { buf . append ( cFormat . substring ( stringLoct , tokenPos ) ) ; int end2Pos ; final char [ ] endTokens = { 'd' , 'f' , 's' , 'x' } ; int c = 0 ; stringLoct = cFormat . indexOf ( endTokens [ c ++ ] , tokenPos ) ; for ( ; c < endTokens . length ; c ++ ) { end2Pos = cFormat . indexOf ( endTokens [ c ] , tokenPos ) ; if ( stringLoct == - 1 || ( end2Pos != - 1 && end2Pos < stringLoct ) ) { stringLoct = end2Pos ; } } stringLoct ++ ; final String tok = cFormat . substring ( tokenPos , stringLoct ) ; obj = args [ tokenCount ++ ] ; final int comma = obj . indexOf ( ',' ) ; final int stop = obj . indexOf ( '.' ) ; if ( ( comma != - 1 && stop != - 1 ) && ( comma < stop ) ) { final StringBuilder str = new StringBuilder ( ) ; char next ; for ( int i = 0 ; i < obj . length ( ) ; i ++ ) { next = obj . charAt ( i ) ; if ( next != ',' ) { str . append ( next ) ; } } obj = str . toString ( ) ; } final String val = convertToken ( tok , obj ) ; buf . append ( val ) ; tokenPos = cFormat . indexOf ( PERCENT , tokenPos + 1 ) ; } if ( stringLoct < cFormat . length ( ) ) { buf . append ( cFormat . substring ( stringLoct ) ) ; } return context . newObject ( scope , "String" , new Object [ ] { buf . toString ( ) } ) ; }
sorts the arguments passed in into a string defined by the template given in cformat , % ( char ) says what type it should be in . there can be as many arguments ( comma - seperated ) as there are % tags in the format string . see page 720 of ' javascript for acrobat api reference '
