Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if my string starts with uppercase character

Tags:

string

iphone

I'm working with cocoa on the iPhone and I'm looking for some method like:

NSString *s = @"Hello";

[s isStringStartsWithUpperCaseCharacter]

-(BOOL) isStringStartsWithUpperCaseCharacter;

The first letter of the string may be non ASCII letter like: Á, Ç, Ê...

Is there some method which can helps me?

I saw in the documentation that there are some methods to convert the string to uppercase and to lowercase but there are no methods for ask if the string is lowercase or uppercase.

like image 981
Aram Avatar asked Nov 29 '22 04:11

Aram


1 Answers

BOOL isUppercase = [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[s characterAtIndex:0]];

Edit:

I'm not sure what's the difference between uppercaseLetterCharacterSet and capitalizedLetterCharacterSet. If someone finds out, please leave a comment!

2nd Edit:

Thanks, Ole Begemann, for finding out about the differences. I edited the code to make it work as expected.

like image 175
Nikolai Ruhe Avatar answered Dec 09 '22 14:12

Nikolai Ruhe