Skip to content

Instantly share code, notes, and snippets.

@boredzo
Created December 18, 2012 05:30
Show Gist options
  • Select an option

  • Save boredzo/4325317 to your computer and use it in GitHub Desktop.

Select an option

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
#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);
}
}
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