Re: Need help to make this method prettier
Re: Need help to make this method prettier
- Subject: Re: Need help to make this method prettier
- From: Louis Demers <email@hidden>
- Date: Sat, 01 Nov 2008 16:07:31 -0400
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:@"d", first];
str1 = [NSString stringWithFormat:@"d", second];
str2 = [NSString stringWithFormat:@"d", third];
check the printf formatting codes for better understanding of the d
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 (email@hidden)
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:
This email sent to email@hidden