Remove excess line breaks
Remove excess line breaks
- Subject: Remove excess line breaks
- From: Rick Anderson <email@hidden>
- Date: Mon, 15 Dec 2003 03:53:43 -0800
I'm trying to remove excess line breaks from a string, replacing any
given number of returns with one single return. If I were doing it in
perl, it would look like this:
$theString =~ s/\r+/\r/g
So, here's what I come up with in Cocoa. If it looks a little
convoluted, well... it is. And it also doesn't work. Any thoughts with
what's wrong with this or possibly a more elegant way to do it would be
appreciated. The first line is just a test to see if the string still
contains any occurrence of a double return; the third line simply runs
through and replaces any double returns with a single return.
if ( (NSEqualRanges ([endString rangeOfString:@"\r\r"],
NSMakeRange(NSNotFound, 0) ) ) == NO)
{
[endString replaceOccurrencesOfString:@"\r\r" withString:@"\r"
options:nil range:NSMakeRange(0, [endString length])];
}
--Rick Anderson
"The only difference between me and a madman,
is that I am not mad." -- Salvador Dali
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.