Thread: change format

    #1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    19
    Rep Power
    0

    change format


    Hi, i need to know how i can change a string from 20020925-2-6 to become 20020925-002-06??

    pls help... thanks...
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    You keep finding these interesting problems

    PHP Code:
    String input "20020925-2-6";

    java.util.StringTokenizer tok = new java.util.StringTokenizerinput"-" );
    if ( 
    tok.countTokens() == ) {
        
    String[] parts = new String[3];
        
    int ndx 0;
        while( 
    tok.hasMoreTokens() ) {
            
    parts[ndx] = tok.nextToken();
            
    ndx++;
        }

        
    java.text.DecimalFormat df1 = new java.text.DecimalFormat"00000000" );
        
    java.text.DecimalFormat df2 = new java.text.DecimalFormat"000" );
        
    java.text.DecimalFormat df3 = new java.text.DecimalFormat"00" );

        
    String output df1.formatDouble.parseDoubleparts[0] ) ) + "-" df2.formatDouble.parseDoubleparts[1] ) ) + "-" df3.formatDouble.parseDoubleparts[2] ) );
        
    out.print( output );
    } else {
        
    out.print( "Shame on you.  The input is the wrong format." );

    Last edited by bricker42; October 1st, 2002 at 02:18 AM.

IMN logo majestic logo threadwatch logo seochat tools logo