-1

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?

Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92
Krishna1251
  • 177
  • 1
  • 10
  • 1
    You don't appear to have read the documentation of `NSString`. This is a trivial problem, and you should not have asked about it **at all.** –  Jun 24 '13 at 10:38

2 Answers2

1

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

Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92
1
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);
}
Girish
  • 4,692
  • 4
  • 35
  • 55