Removing new line characters from NSString

前端 未结 5 1731
我寻月下人不归
我寻月下人不归 2020-12-03 00:55

I have a NSString like this:

Hello 
World
of
Twitter
Lets See this
>

I want to transform it to:

Hel

5条回答
  •  难免孤独
    2020-12-03 01:11

    Split the string into components and join them by space:

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

提交回复
热议问题