I am developing a iOS Chat Application, Here i have a scenario where i have to identify user entered text contains any Abusing words on my submit button action.I have a big list of abuse words to identify.
I have used the below code to identify the abusing words ,but iam facing a problem here for example. my list of abusing words Array contains "Hell". if i enter "Hello" in textfield its showing as abusing word ,because Hello contains Hell.
Here is my code
NSArray *arrayOfStrings = [[rateQuery findObjects] mutableCopy];
arrayOfStrings=[arrayOfStrings valueForKey:@"Words"];//List of Abusing words
NSString *stringToSearchWithin = nameFld.text;//user entered text
__block NSString *result = nil;
[arrayOfStrings indexOfObjectWithOptions:NSEnumerationConcurrent
passingTest:^(NSString *obj, NSUInteger idx, BOOL *stop)
{
if ([stringToSearchWithin rangeOfString:obj].location != NSNotFound)
{
result = obj;
*stop = YES;
//return YES;
}
return NO;
}];
if (!result){
NSLog(@"The string does not contain any of the strings from the arrayOfStrings");
}
else
{
NSLog(@"The string contains Abusing words");
}