views:

41

answers:

2

Hey! I was wondering if there was any way to check if the first letter of a string was capital or not in an NSString. Something similar to:

if ([[string substringToIndex:1] isCapitalLetter]) {
    // CODE
}

--or--

if ([self isCapitalLetter:[string substringToIndex:1]]) {
    // CODE
}
+5  A: 

[[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[myString characterAtIndex:0]];

Peter DeWeese
A: 

The only thing I can think of would be to do something like this:

// get the first character, capitalized
NSString *capital = [[oldstring substringToIndex:1] capitalizedString];

// then compare to your oldstring
if ( [[oldstring substringToIndex:1] isEqualToString:capital] ) {
    // do stuff...
}

The NSString reference is your friend: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html

livingtech