Created
December 5, 2015 04:33
-
-
Save mortenjust/3d9904917e9a238cd020 to your computer and use it in GitHub Desktop.
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
func wordRangeAtIndex(index:Int, inString str:NSString) -> NSRange { | |
let tagger = NSLinguisticTagger(tagSchemes: [NSLinguisticTagSchemeTokenType], options: 0) | |
var r : NSRange = NSMakeRange(0,0) | |
tagger.string = str as String | |
tagger.tagAtIndex(index, scheme: NSLinguisticTagSchemeTokenType, tokenRange: &r, sentenceRange: nil ) | |
return r | |
} | |
func wordAtIndex(index:Int, inString str:NSString) -> NSString { | |
return str.substringWithRange(wordRangeAtIndex(index, inString: str)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment