I have an NSString
which can have multiple \\n in between the string. I need to replace the multiple occurrence of \\n\'s with a single \\n.
I tried this co
You might use NSRegularExpression. This is the most simple and elegant way:
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\n+" options:0 error:NULL];
NSString *newString = [regex stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:@"\n"];