I have NSStringone that can have several \ n between the lines. I need to replace multiple occurrence \ n with one \ n.
I tried this code:
newString = [string stringByReplacingOccurrencesOfString:@"\n\n" withString:@"\n"];
But this does not give the desired result if the string contains the series "\ n \ n \ n \ n \ n \ n". In this case, they will be replaced by "\ n \ n \ n".
What should I do to replace multiple "\ n" with one "\ n"?
Thanks everyone!
Update: adding a screenshot for UITextViewto which the filtered string is set as text. It seems that new lines look more than after writing code, as suggested by Attila H in response.
