Breaking News
Home / iOS / ObjectiveC / How to check if a String contains another String in Objective C?

How to check if a String contains another String in Objective C?

Answer

NSString *haystack = @”welcome to the mall”;

NSString *needle = @”mall”;

if ([haystack rangeOfString:needle].location == NSNotFound)

NSLog(@”needle not found in haystack”);}

else

{

  NSLog(@”needle found in haystack.”);

}

[pb_builder]

Check Also

Singleton Example in Objective C?

Solution static MyManager *sharedManager = nil; +(MyManager*) sharedManager {         if (sharedManager == nil)         …

Leave a Reply