String trim in Objective-C/Cocoa

To trim a string and remove whitespace and newlines:

NSString *trimmedString = [dirtyString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

For other character sets, see this reference page.

Comments