喂!我想知道是否有任何方法可以检查字符串的第一个字母是否是NSString中的大写字母。类似于:
if ([[string substringToIndex:1] isCapitalLetter]) {
// CODE
}
- 或 -
if ([self isCapitalLetter:[string substringToIndex:1]]) {
// CODE
}
答案 0 :(得分:18)
[[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[myString characterAtIndex:0]];
答案 1 :(得分:2)
我唯一能想到的就是做这样的事情:
// get the first character, capitalized
NSString *capital = [[oldstring substringToIndex:1] capitalizedString];
// then compare to your oldstring
if ( [[oldstring substringToIndex:1] isEqualToString:capital] ) {
// do stuff...
}
NSString引用是你的朋友:http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html