Is there a Objective-c function to return a NSString *
from a NSUInteger
, i.e.:
- 1 -> 1st
- 2 -> 2nd
- ...
- 10 -> 10th
- 21 -> 21st
- ...
- 31 -> 31st
for the range from 1 to 31. Thanks!
Is there a Objective-c function to return a NSString *
from a NSUInteger
, i.e.:
for the range from 1 to 31. Thanks!
- (NSString *)stringFromInt:(int)num {
NSString stringAddition;
if (num >= 11 && num <= 13) {
strinAddition = @"th";
}
else {
switch (num % 10) {
case 1: stringAddition = @"st"; break;
case 2: stringAddition = @"nd"; break;
case 3: stringAddition = @"rd"; break;
default: stringAddition = @"th"; break;
}
}
return [NSString stringWithFormat:@"%i%@", num, stringAddition];
}
EDIT:
Fixed the 11, 12, 13 issue.