Trimming Newlines (\n) from NSStrings

Wow, what a lesson in heartache for such a simple little need.

I’m walking an NSDictionary and need to output the results. Not a hard task. No, not at all.

Except that my source data (API call, long story) is prepending all text nodes with a \n. Or it could be the XML to Dictionary code I picked up and threw into the class like there was no tomorrow.

After several lacklustre searches on Google. I found this:

NSString *newString = [oldString stringByTrimmingCharactersInSet:
[NSCharacterSet newlineCharacterSet]];

Pretty simple when you get right down to it, but still, it took me a little while to find the solution.