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 = [mySt开发者_如何转开发ring componentsSeparatedByString:@" "];
if ([explodedDescription objectAtIndex:1] == @"Programa" ) {
NSLog(@"Found");
}
NSStrings are compared with isEqualToString. You're comparing pointers instead of the values.
See NSString documentation
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.
精彩评论