不良词汇过滤

1、得到过滤数组

NSError *error;

NSString *path = [[NSBundle mainBundle]pathForResource:@"forbid" ofType:@"txt"];

NSString * content = [NSString stringWithContentsOfFile:path encoding:NSUTF16StringEncoding error:&error];

if (error) {

NSLog(@"过滤错误%@",error.localizedDescription);

}

self.contarray = [content componentsSeparatedByString:@","];

2、过滤替换

for (NSString *str in self.contarray) {

if([self.textTF.text rangeOfString:str].location !=NSNotFound){

NSString *replaceStr = [self.textTF.text stringByReplacingCharactersInRange:NSMakeRange([self.textTF.text rangeOfString:str].location, str.length) withString:@"***"];

self.textTF.text = replaceStr;

break;

}

}



3


3

3

你可能感兴趣的:(不良词汇过滤)