iOS分词 发表于 2016-10-25 | 分类于 iOS | 最近锤子科技发布新手机,手机推出重大功能分词(Big Bang),其实 iOS 拥有分词的 API,代码如下 123456789101112131415- (NSArray *)stringTokenizerWithWord:(NSString *)word { NSMutableArray *keyWords = [NSMutableArray new]; CFStringTokenizerRef ref = CFStringTokenizerCreate(NULL, (__bridge CFStringRef)word, CFRangeMake(0, word.length),kCFStringTokenizerUnitWord,NULL); CFRange range; NSString *keyWord; do { CFStringTokenizerAdvanceToNextToken(ref); range = CFStringTokenizerGetCurrentTokenRange(ref); if (range.length == 0) break; keyWord = [word substringWithRange:NSMakeRange(range.location, range.length)]; [keyWords addObject:keyWord]; } while (range.length > 0); return keyWords;}