是否有Objective-c函数从NSString *
返回NSUInteger
,即:
范围从1到31.谢谢!
答案 0 :(得分:7)
- (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];
}
修改的:
修正了11,12,13号问题。