Alex Rivera | Logout

get NSString first word only

Asked 2012-11-28T09:23:51.677
11

I am having this NSString, that gives me the user language .

NSString * language= @"English (America) " ;

I need to get from it ONLY the first word- which is the language . I know how to find space, but could not find a simple way to get only the first word.

ThAnks.

Edit
Report

1 Answer

6
NSUInteger location = [language rangeOfString:@" ("].location;
NSString *result = location == NSNotFound ? language : [language substringToIndex:location];
answered 2012-11-28T09:30:49.567

Your Answer