过滤敏感

/**

*  过滤敏感词汇

*

*  @return YES/NO

*/

+ (BOOL)checkIllegalWords:(NSString *)words {

// 读取文件

NSString *filterPath = [[NSBundle mainBundle] pathForResource:@"filter" ofType:@"txt"];

NSString *filterStr = [[NSString alloc] initWithContentsOfFile:filterPath encoding:NSUTF8StringEncoding error:nil];

NSArray *filterArr = [filterStr componentsSeparatedByString:@"\r\n"];

BOOL isLegal = YES;

for (NSString *oneItem in filterArr) {

if ([words rangeOfString:oneItem].location != NSNotFound) {

isLegal = NO;

break;

}

}

return isLegal;

}

你可能感兴趣的:(过滤敏感)