-1

I wanted to search for a string: @"Data " (including the space at the end) in the string (NSString *info). What should I do?

The string that is being searched has a space. Instead of @'data', I'm trying to find @'data '.

  • how is your `info` string ? – caldera.sac Oct 08 '16 at 03:17
  • Possible duplicate of [How do I check if a string contains another string in Objective-C?](http://stackoverflow.com/questions/2753956/how-do-i-check-if-a-string-contains-another-string-in-objective-c) – HAS Oct 08 '16 at 06:43

2 Answers2

2

I don't know if i understand wich you want to do. But if you want to check if string contains in another string you need to do this:

NSString *yourString = @"Data your string";
if ([yourString rangeOfString:@"Data "].location == NSNotFound) {
  NSLog(@"not contains Data ");
} else {
  NSLog(@"contains Data ");
}
0

try this:

    NSString *mainString = @"Your Data ";
    NSRange stringRange = [mainString rangeOfString:@"Data "
                           options:NSCaseInsensitiveSearch];
    NSString *subString = [mainString substringWithRange:stringRange];
    NSLog(@"substring :%@",subString);
amit_donga
  • 224
  • 1
  • 9