I need to replace the standard upper double quotes “” that already exist (in text I get from a database) with specific quotes for german text for use in a UIWebView.
The first double quote character before the quoted word(s) (every even index) needs to be replaced with the HTML equivalent of „ which is „ and the second one after the quoted word(s) (every odd index) with “ which is “. The quotes can be anywhere in the text, so I can’t rely on any fixed positions.
So basically I have a NSString like this:
just “some” text with some “more” text
or in Objective-C:
NSString *str = @"just \"some\" text with some \"more\" text";
I am aware of the stringByReplacingOccurrencesOfString method from NSString, but of course this only replaces all double quotes with the bottom double quote mark.
NSString *newStr = [str stringByReplacingOccurrencesOfString:@"\"" withString:@"„"];
I couldn’t find a way to just replace every second or every n-th occurrence, does someone have a hint/idea how I could accomplish that?
Thanks a lot
NSScanneroffers another option…