Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing new line characters from NSString

I have a NSString like this:

Hello  World of Twitter Lets See this > 

I want to transform it to:

Hello World of Twitter Lets See this >

How can I do this? I'm using Objective-C on an iPhone.

like image 860
y ramesh rao Avatar asked Nov 27 '09 10:11

y ramesh rao


People also ask

What is the difference between NSString and string?

Secondly, in Swift String is a struct, while in Objective-C, NSString is a class and inherit from NSObject . In concept, Swift String is more likely immutable. If we use a struct type and constant (remember the let keyword), we can keep out a lot of consideration of multi-thread programming and make us a better life.


1 Answers

Split the string into components and join them by space:

NSString *newString = [[myString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@" "]; 
like image 52
hallski Avatar answered Oct 09 '22 02:10

hallski