You can perform this complex string replacement with regular expressions .
You can write an expression using negative lookbehind to find (which is not preceded +(although there are simpler alternatives in this case, see @sch's comment).
Example:
NSString *string = @"(Mg(Ni+(N(O2)3";
NSLog(@"Original string: %@", string);
NSString *pattern = @"(?<!\\+)\\(";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:NULL];
NSString *modifiedString = [regex stringByReplacingMatchesInString:string
options:0
range:NSMakeRange(0, [string length])
withTemplate:@"$1+"];
NSLog(@"After replacement: %@", modifiedString);
source
share