Your going to need the "while" loop to run the replace a number of times until there are no double spaces. The replaceOccurrencesOfString: returns the number of replacements that took place, so adding it to a while loop is enough.
Code: Select all
while ([cleanString replaceOccurrencesOfString:@"\n\n" withString:@"\n" options:NSLiteralSearch range:NSMakeRange(0, [cleanString length])] != 0);
The "!= 0" is not needed and can be implicit, but I put it
in to make clear what is happening.
Your doing really well for recently diving into Cocoa and objective-C. It's a documentation heavy language as there is so much to it. Inheritance is one of the tricky parts to remember. That an object might respond to more messages than are
in NSString, that it might be a subset or that it has parents that have more methods. Speaking of NSMutableString, make sure to turn the string you pass into the method into a NSMutableString if necessary, just like the other clean method.