S.J. Lim
S.J. Lim

Reputation: 3165

Is there a class or way that find strings in nsstring?

NSString *string = @"ABCDEFG";
NSString *FindString = @"DG";

BOOL result = [string containString(????):FindString];

I want a result if FindString is contained in string.

Because 'D' and 'G' is contained into string, above result is YES.

Is there a simple way to do this?

Upvotes: 0

Views: 83

Answers (3)

hburde
hburde

Reputation: 1441

You can use NSRegularExpression which return ranges with matching expressions.

Upvotes: 0

Saurabh Passolia
Saurabh Passolia

Reputation: 8109

to check a subString you can use,

if (![string rangeOfString:FindString].length == 0)
{
  // not found
}
else
{
  // found
}

Upvotes: 0

Joshua Weinberg
Joshua Weinberg

Reputation: 28688

Something along the lines of..

NSCharacterSet *outerSet = [NSCharacterSet characterSetWithCharactersInString:@"ABCDEFG"];
NSCharacterSet *innerSet = [NSCharacterSet characterSetWithCharactersInString:@"DG"];
BOOL result = [outserSet isSupersetOfSet:innerSet];

Upvotes: 2

Related Questions