Answers:
来吧:
viewNoteDateMonth.text = [[displayDate objectAtIndex:2] uppercaseString];
顺便说一句:
"april"
是lowercase
➔ [NSString lowercaseString]
"APRIL"
是UPPERCASE
➔ [NSString uppercaseString]
"April May"
是Capitalized/Word Caps
➔ [NSString capitalizedString]
"April may"
是Sentence caps
➔(方法缺失;请参见下面的解决方法)
因此,您想要的是“ 大写 ”,而不是“ 大写 ”。;)
至于“句子上限”,必须记住通常“句子”的意思是“整个字符串”。如果您希望使用真实句子,请使用下面的第二种方法,否则使用第一种方法:
@interface NSString ()
- (NSString *)sentenceCapitalizedString; // sentence == entire string
- (NSString *)realSentenceCapitalizedString; // sentence == real sentences
@end
@implementation NSString
- (NSString *)sentenceCapitalizedString {
if (![self length]) {
return [NSString string];
}
NSString *uppercase = [[self substringToIndex:1] uppercaseString];
NSString *lowercase = [[self substringFromIndex:1] lowercaseString];
return [uppercase stringByAppendingString:lowercase];
}
- (NSString *)realSentenceCapitalizedString {
__block NSMutableString *mutableSelf = [NSMutableString stringWithString:self];
[self enumerateSubstringsInRange:NSMakeRange(0, [self length])
options:NSStringEnumerationBySentences
usingBlock:^(NSString *sentence, NSRange sentenceRange, NSRange enclosingRange, BOOL *stop) {
[mutableSelf replaceCharactersInRange:sentenceRange withString:[sentence sentenceCapitalizedString]];
}];
return [NSString stringWithString:mutableSelf]; // or just return mutableSelf.
}
@end
viewNoteDateMonth.text = [[displayDate objectAtIndex:2] uppercaseString];