Reputation: 1
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.
Upvotes: 11
Views: 9077
Reputation: 3547
Here is my answer:
NSString * language= @"English (America) " ;
NSArray *comps = [language componentsSeparatedByString:@" "];
NSString * eng = [comps objectAtIndex:0];
Upvotes: 2
Reputation: 81868
NSUInteger location = [language rangeOfString:@" ("].location;
NSString *result = location == NSNotFound ? language : [language substringToIndex:location];
Upvotes: 6
Reputation: 77641
NSString *firstWord = [[language componentsSeparatedByString:@" "] objectAtIndex:0];
Upvotes: 48