Reputation: 31
Is there a way we can use nspredicate like this?
String = whvat
I want to search the string if it contains these characters [what]{4}. This will not return true for the above string since v is not found. I basically want a predicate to return true if a string contains 'n' specified characters. There can be other characters in the string but the specified should be definitely present. Order of characters does not matter. Even if I give [hwta] it should still give me the word whvat because 4 specified characters are found
Upvotes: 2
Views: 235
Reputation: 71
This is not very elegant but you could try to make predicate for each character:
NSPredicate *p = [NSPredicate predicateWithFormat:@"self contains 'w' and self contains 'h' and self contains 'a' and self contains 't'"];
NSString *string = @"what";
NSLog(@"%d ", [p evaluateWithObject:string]);
Upvotes: 1