How to identify and remove newline and white spaces?

ios, xcode

Solution

If you want an array without whitespace:

NSString *string = @"Hello, World!";
NSCharacterSet *separator = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSArray *stringComponents = [string componentsSeparatedByCharactersInSet:separator];

Problem

I am making an nsmutable array by separating a string by component it is causing a lot of new line and white spaces to be inserted in the array how to identify and remove them? ``` for (int i=0;i<contentsOfFile.count; i++) { if(!([[contentsOfFile objectAtIndex:i]isEqual:@"\n"]||[[contentsOfFile objectAtIndex:i]isEqual:@""])) [arrayToBereturned addObject:[contentsOfFile objectAtIndex:i]]; } ``` this code which i am using cannot identify all new line charectors thanks

Original source