Created
December 18, 2012 05:30
-
-
Save boredzo/4325317 to your computer and use it in GitHub Desktop.
Testing NSString compare:options:range: with a prefix range that is equal in both strings
This file contains hidden or 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
| #import <Foundation/Foundation.h> | |
| //References: | |
| // http://stackoverflow.com/q/13918360/30461 | |
| // http://lists.apple.com/archives/carbon-dev/2005/Aug/msg00525.html | |
| //I ported this code to Objective-C/NSString. | |
| int main(int argc, char *argv[]) { | |
| @autoreleasepool { | |
| NSString *string1 = @"http://idisk.mac.com/"; | |
| NSString *string2 = @"http://idisk.mac.com/ktam2/"; | |
| NSUInteger shortLength = [string1 length]; | |
| NSComparisonResult result1 = [string1 compare:string2 | |
| options:0 | |
| range:(NSRange){ 0, shortLength }]; | |
| NSLog(@"%ld", result1); | |
| NSComparisonResult result2 = [string2 compare:string1 | |
| options:0 | |
| range:(NSRange){ 0, shortLength }]; | |
| NSLog(@"%ld", result2); | |
| } | |
| } |
This file contains hidden or 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
| 2012-12-17 21:27:34.211 Untitled[10696:707] -1 | |
| 2012-12-17 21:27:34.219 Untitled[10696:707] 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment