I have a textview which can take any input and I need to parse the quotes and double quotes as '
and "
respectively. So if I input a text in my text view like "Just testin'g quotes" the output should be "Just testin'g quotes"
Below is my code for parsing and it works fine so far.
-(NSString *)parseQuotes:(NSMutableString *)str {
[str replaceOccurrencesOfString:@"\"" withString:@""" options:0 range:NSMakeRange(0, [str length])];
[str replaceOccurrencesOfString:@"'" withString:@"'" options:0 range:NSMakeRange(0, [str length])];
return str;
}
So, now my problem is if I'm copy pasting a text like below
“Just testin’g quotes”
"Just testin'g quotes"
It gives me a output like
“Just testin’g quotes”
"Just testin'g quotes"
Notice how the first one didn't parse as it has the quotes and double quotes in a different format. So for this I need to duplicate the same code with these new quotes like
[str replaceOccurrencesOfString:@"“" withString:@""" options:0 range:NSMakeRange(0, [str length])];
[str replaceOccurrencesOfString:@"”" withString:@""" options:0 range:NSMakeRange(0, [str length])];
[str replaceOccurrencesOfString:@"’" withString:@"'" options:0 range:NSMakeRange(0, [str length])];
This works, but I need to know if this is the right way to proceed? Is there a possibility a different kind quote could appear and break this code? Is there a better alternative solution for this which will work for all types of quotes?