Tuesday, August 31, 2010

Trim String in Object C

This is how to trim a string and remove whitespace and newlines:

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


For other character sets, refer to
http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSCharacterSet_Class/Reference/Reference.html#//apple_ref/doc/uid/20000157-SW5.

No comments:

Post a Comment