开发者

NSArray element comparison to NSString

开发者 https://www.devze.com 2022-12-15 11:01 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消