Created
April 17, 2015 01:32
-
-
Save Koze/0f9f47a32cec0890e323 to your computer and use it in GitHub Desktop.
Predicate with wildcard vs BEGINSWITH and ENDSWITH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)testWildcard3 | |
{ | |
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF LIKE[c] 'a*a'"]; | |
NSLog(@"%@", predicate); | |
// SELF LIKE[c] "a*a" | |
NSLog(@"%d", [predicate evaluateWithObject:@"a"]); | |
// 0 | |
NSLog(@"%d", [predicate evaluateWithObject:@"aa"]); | |
// 1 | |
NSLog(@"%d", [predicate evaluateWithObject:@"aba"]); | |
// 1 | |
} | |
- (void)testWildcard4 | |
{ | |
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH[c] 'a' AND SELF ENDSWITH[c] 'a'"]; | |
NSLog(@"%@", predicate); | |
// SELF BEGINSWITH[c] "a" AND SELF ENDSWITH[c] "a" | |
NSLog(@"%d", [predicate evaluateWithObject:@"a"]); | |
// 1 | |
NSLog(@"%d", [predicate evaluateWithObject:@"aa"]); | |
// 1 | |
NSLog(@"%d", [predicate evaluateWithObject:@"aba"]); | |
// 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment