NSString删除换行符(Objective-C)

时间:2015-01-17 20:48:00

标签: objective-c nsstring

我将数据从XML加载到我的NSString,但数据的格式如下:

    Lorem ipsum dolor sit amet, 
    consectetur adipiscing elit. 
    Sed a velit ut nulla tincidunt finibus sit amet sed felis. 
    Fusce quis quam sapien.

它有换行符,如何删除它以使文本看起来像这样(全部在一行):

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a velit ut nulla tincidunt finibus sit amet sed felis. Fusce quis quam sapien. Cras diam metus, viverra in urna sed, efficitur varius sem. Pellentesque accumsan, lectus at rutrum pulvinar, 

1 个答案:

答案 0 :(得分:0)

试试这个

NSString *newString = [[oldString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@" "];