NSString replace repeated newlines with single newline

前端 未结 3 1333
孤独总比滥情好
孤独总比滥情好 2021-02-04 20:06

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

3条回答
  •  -上瘾入骨i
    2021-02-04 20:41

    You can do it in the following way

    NSArray *arrSplit = [s componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
                    s = [arrSplit componentsJoinedByString:@"\n"];
    

    Hope it may help you..

提交回复
热议问题