Is there a Objective-c function to return a NSString *
from a NSUInteger
, i.e.:
for the range from 1 to 31. Thanks!
What are ordinal numbers from 1 to 10? The ordinal numbers from 1 to 10 are 1st – First, 2nd – Second, 3rd – Third, 4th – Fourth, 5th – Fifth, 6th – Sixth, 7th – Seventh, 8th – Eighth, 9th – Ninth and 10th – Tenth, respectively.
- (NSString *)stringFromInt:(int)num {
NSString stringAddition;
if (num%100 >= 11 && num%100 <= 13) {
stringAddition = @"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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With