Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C String Function: Contains String

How can I check if an NSString contains another substring, at which point it will return a Boolean Value.

This is what I'm thinking of:

If myString.contains("string") then
{
   //Stuff Happens
}

But, from the research I've done, it seems as if Obj-C has no function for this. This Wikipedia article gives numerous string functions, their differences, and all in different languages, but I see no Obj-C support for any Contain Function.

Does anyone know of a simple-to-use function like the once above (which is similar to the C# and VB.NET function)?

Would a "Find" Function work? If so, how?

If this is not supported in Obj-C, is there a workaround I can use?

Any help is very appreciated.

like image 795
Sam Spencer Avatar asked Nov 28 '22 17:11

Sam Spencer


1 Answers

if ([myString rangeOfString:@"string"].location != NSNotFound)
{
    // Stuff happens
}
like image 184
Andrew Madsen Avatar answered Dec 05 '22 04:12

Andrew Madsen