Here is some code that removes white space from a string, like new lines, tabs, and double spaces (not single spaces). It’s intended as to be used in an NSString category. Example could be [@” h\nello\r” removeWhiteSpace] would return @”hello”

Note: this is not to use as a trim function, for that use CFStringTrimWhitespace ((CFMutableStringRef) yourStringHere);

Sounds nifty. Could be useful for someone trying to write an interpreter in Cocoa. –OwenAnderson

What you’re doing is removing double spaces entirely - so if I wrote “This is a test.” I’d get back “This is atest.”
Since often when removing whitespace this isn’t quite ideal, the following added in in place of the two-spacer works: