NSString *trimmedString = [dirtyString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
For other character sets, see this reference page.
Today, I ran across a use case where, unless I'm missing something, using an informal protocol is the only viable solution. Take this scenario:
@protocol MyProtocol <NSObject>) won't help you if you need to send performSelectorOnMainThread:withObject:waitUntilDone: messages to objects that conform to it (e.g., id myObj; ). That's because the NSObject protocol doesn't declare that method.
Instead, declare the type of your objects as NSObject conforming to your protocol like this: