Search code examples
objective-cstringspacestring-search

How to search a string with space within another string in objective-C?


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 '.


Solution

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