Вопрос

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?

Это было полезно?

Решение

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);
}

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top