Created
November 16, 2012 15:25
-
-
Save ksm/4088176 to your computer and use it in GitHub Desktop.
Extract date from natural language string
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
/* | |
Extract date from natural language string | |
Source: WWDC2012 Session 215 - Text and Linguistic Analysis | |
*/ | |
NSDataDetector *dateDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeDate error:nil]; | |
NSString *dateString = @"13th September 1986 11:59pm"; | |
NSTextCheckingResult *result = [dateDetector firstMatchInString:dateString | |
options:0 | |
range:NSMakeRange(0, [dateString length])]; | |
if (result.resultType == NSTextCheckingTypeDate) { | |
NSLog(@"%@", result.date); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment