Reputation: 2145
I am trying to find a word inside a phrase (NSString).
For this I've exploded the components of the phrase into individual substrings and now I am trying to compare them to the word I am looking for, but it doesn't work.
What would be the correct approach for this and fix for the software below?
NSString *myString = @"Mi Programa es genial";
NSArray *explodedDescription = [myString componentsSeparatedByString:@" "];
if ([explodedDescription objectAtIndex:1] == @"Programa" ) {
NSLog(@"Found");
}
Upvotes: 0
Views: 1192
Reputation:
You're doing it the hard way! Use NSString's -rangeOfString: method or one of its variants to get the location of a string in another string.
Upvotes: 2
Reputation: 29333
NSStrings are compared with isEqualToString. You're comparing pointers instead of the values.
Upvotes: 7