Sam Sam - 3 months ago 27
Objective-C Question

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.

Answer
if ([myString rangeOfString:@"string"].location != NSNotFound)
{
    // Stuff happens
}