Quantcast
Channel: How do I check if a string contains another string in Objective-C? - Stack Overflow
Browsing all 22 articles
Browse latest View live

Answer by Amir.n3t for How do I check if a string contains another string in...

Try this: Swift 4.1 , 4.2:let stringData = "Black board"//swift quick way and case sensitiveif stringData.contains("bla") { print("data contains string");}//case sensitiveif stringData.range(of:...

View Article



Answer by midhun p for How do I check if a string contains another string in...

Swift 4 And Abovelet str = "Hello iam midhun"if str.contains("iam") { //contains substring}else { //doesn't contain substring}Objective-CNSString *stringData = @"Hello iam midhun";if ([stringData...

View Article

Answer by Nayab Muhammad for How do I check if a string contains another...

Use the option NSCaseInsensitiveSearch with rangeOfString:options:NSString *me = @"toBe" ;NSString *target = @"abcdetobe" ;NSRange range = [target rangeOfString: me options:...

View Article

Answer by Kamani Jasmin for How do I check if a string contains another...

First string contain or not second string,NSString *first = @"Banana";NSString *second = @"BananaMilk";NSRange range = [first rangeOfString:second options:NSCaseInsensitiveSearch];if (range.length >...

View Article

Answer by garg for How do I check if a string contains another string in...

In Swift 4:let a = "Hello, how are you?"a.contains("Hello") //will return true

View Article


Answer by handiansom for How do I check if a string contains another string...

Best solution. As simple as this! If you want to find a word or part of the string. You can use this code. In this example we are going to check if the value of word contains "acter".NSString *word...

View Article

Answer by Sreedeepkesav M S for How do I check if a string contains another...

In case of swift, this can be used let string = "Package #23"if string.containsString("Package #") { //String contains substring}else { //String does not contain substring}

View Article

Answer by Pooja Patel for How do I check if a string contains another string...

try this,NSString *string = @"test Data";if ([[string lowercaseString] rangeOfString:@"data"].location == NSNotFound) { NSLog(@"string does not contain Data");} else { NSLog(@"string contains data!");}

View Article


Answer by ucangetit for How do I check if a string contains another string in...

So personally I really hate NSNotFound but understand its necessity.But some people may not understand the complexities of comparing against NSNotFoundFor example, this code:-...

View Article


Answer by Rohit suvagiya for How do I check if a string contains another...

Please use this codeNSString *string = @"hello bla bla";if ([string rangeOfString:@"bla"].location == NSNotFound) { NSLog(@"string does not contain bla");} else { NSLog(@"string contains bla!");}

View Article

Answer by Ada for How do I check if a string contains another string in...

NSString *categoryString = @"Holiday Event";if([categoryString rangeOfString:@"Holiday"].location == NSNotFound){ //categoryString does not contains Holiday}else{ //categoryString contains Holiday}

View Article

Answer by Abhijit for How do I check if a string contains another string in...

If do not bother about case-sensitive string. Try this once.NSString *string = @"Hello World!";if([string rangeOfString:@"hello" options:NSCaseInsensitiveSearch].location !=NSNotFound){...

View Article

Answer by Nikolay Shubenkov for How do I check if a string contains another...

If you need this once write:NSString *stringToSearchThrough = @"-rangeOfString method finds and returns the range of the first occurrence of a given string within the receiver.";BOOL contains =...

View Article


Answer by Govind for How do I check if a string contains another string in...

With iOS 8 and Swift, we can use localizedCaseInsensitiveContainsString method let string: NSString = "Café" let substring: NSString = "É" string.localizedCaseInsensitiveContainsString(substring) // true

View Article

Answer by Lukas for How do I check if a string contains another string in...

Since this seems to be a high-ranking result in Google, I want to add this:iOS 8 and OS X 10.10 add the containsString: method to NSString. An updated version of Dave DeLong's example for those...

View Article


Answer by Durai Amuthan.H for How do I check if a string contains another...

Here is a copy-and-paste function snippet:-(BOOL)Contains:(NSString *)StrSearchTerm on:(NSString *)StrText{ return [StrText rangeOfString:StrSearchTerm options:NSCaseInsensitiveSearch].location !=...

View Article

Answer by vikingosegundo for How do I check if a string contains another...

An improved version of P i's solution, a category on NSString, that not only will tell, if a string is found within another string, but also takes a range by reference, is:@interface NSString...

View Article


Answer by jerik for How do I check if a string contains another string in...

Oneliner (Smaller amount of code. DRY, as you have only one NSLog): NSString *string = @"hello bla bla";NSLog(@"String %@", ([string rangeOfString:@"bla"].location == NSNotFound) ? @"not found" :...

View Article

Answer by AJS for How do I check if a string contains another string in...

NSString *myString = @"hello bla bla";NSRange rangeValue = [myString rangeOfString:@"hello" options:NSCaseInsensitiveSearch];if (rangeValue.length > 0){ NSLog(@"string contains hello");} else {...

View Article

Answer by P i for How do I check if a string contains another string in...

For iOS 8.0+ and macOS 10.10+, you can use NSString's native containsString:.For older versions of iOS and macOS, you can create your own (obsolete) category for NSString:@interface NSString (...

View Article
Browsing all 22 articles
Browse latest View live




Latest Images