0

I have an NSString and am attempting to find the first location of either of three strings @"aaa" and @"bbb" and @"ccc".

range = [text rangeOfString:@"aaa" options:NSCaseInsensitiveSearch range:NSMakeRange(rangeStart, rangeLength)];

Is there any simple way to add a logical operator (or) to the rangeOfString: method? I tried rangeOfString:(@"aaa" || @"bbb" || @"ccc") but it threw an exception. Or is there a simple workaround. Thanks.

2 Answers 2

2

Use Regular Expression

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(aaa|bbb|ccc)" options:0 error:NULL];
NSTextCheckingResult *match = [regex firstMatchInString:text options:0 range:NSMakeRange(0, [text length])];

Hope this helps...

Sign up to request clarification or add additional context in comments.

Comments

0
[[NSRegularExpression regularExpressionWithPattern: @"(aaa|bbb|ccc)" options: NSRegularExpressionCaseInsensitive error: &error] rangeOfFirstMatchInString: text options: 0 range: NSMakeRange(rangeStart, rangeLength)]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.