I am trying to find list of words , if matches i am replacing. the blow code works but it is not replacing if the matching word occurs more than one time.
And i think i need to use while instead of if loop here , but i am not able to make it to work.
I am struggling Please let me know
NSString *mymessage = @"for you for your information at you your at fate";
NSMutableArray *full_text_list = [[NSMutableArray alloc]init];
[full_text_list addObject:@"for"];
[full_text_list addObject:@"for your information"];
[full_text_list addObject:@"you"];
[full_text_list addObject:@"at"];
NSMutableArray *short_text_list = [[NSMutableArray alloc]init];
[short_text_list addObject:@"4"];
[short_text_list addObject:@"fyi"];
[short_text_list addObject:@"u"];
[short_text_list addObject:@"@"];
for(int i=0;i<[full_text_list count];i++)
{
NSRange range = [mymessage rangeOfString:[full_text_list objectAtIndex:i]];
if(range.location != NSNotFound) {
NSLog(@"%@ found", [full_text_list objectAtIndex:i]);
mymessage = [mymessage stringByReplacingCharactersInRange:range withString:[short_text_list objectAtIndex:i]];
}
}