NSString *string1 = @"ball,fruit,doll";
NSString *string2 = @"ball";
if ([string1 rangeOfString:string2].location == NSNotFound)
{
NSLog(@"string does not contain %@", string2);
}
else
{
NSLog(@"string contains %@", string2);
}
How to Compare Two Different Strings (string1 contains string2) [closed]
-
01-06-2022 - |
문제
I am having Two Strings:string1 and string2. String1 contains only "ball", string2 contains "ball,fruit,doll".
Now i need to compare the string1 and string2, ball is in both the strings or not? and i need to remove the ball after comparing the strings. How to acheive this?
해결책
다른 팁
To compare strings you can use isEqualToString
To find out whether one string contains another one you can use rangeOfString
Take a look at the documentation of NSString, the problem is really trivial: http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSString_Class/Reference/NSString.html
제휴하지 않습니다 StackOverflow