On 1-Nov-08, at 13:56 , Andre Masse wrote:

The version I did get the job done but its not pretty :-) Any more good looking solutions?

        
        if (first < 10) {
                str0 = [NSString stringWithFormat:@"00%d", first];
        }
        else if (first < 100){
                str0 = [NSString stringWithFormat:@"0%d", first];
        }
        else {
                str0 = [NSString stringWithFormat:@"%d", first];
        }


        
        if (second < 10) {
                str1 = [NSString stringWithFormat:@"00%d", second];
        }
        else if (second < 100){
                str1 = [NSString stringWithFormat:@"0%d", second];
        }
        else {
                str1 = [NSString stringWithFormat:@"%d", second];
        }
        
        if (third < 10) {
                str2 = [NSString stringWithFormat:@"00%d", third];
        }
        else if (third < 100){
                str2 = [NSString stringWithFormat:@"0%d", third];
        }
        else {
                str2 = [NSString stringWithFormat:@"%d", third];
        }

all the lines above can be replaced by
        

        str0 = [NSString stringWithFormat:@"%03d", first];
        str1 = [NSString stringWithFormat:@"%03d", second];
        str2 = [NSString stringWithFormat:@"%03d", third];


check the printf formatting codes for better understanding of the %03d

the 3 specifies to allways use 3 columns and the 0 specifies to use 0 instead of spaces to fill in the 3 columns



Louis Demers eng.
www.obzerv.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to