Re: Remove excess line breaks
Re: Remove excess line breaks
- Subject: Re: Remove excess line breaks
- From: Stephane Sudre <email@hidden>
- Date: Mon, 15 Dec 2003 14:14:02 +0100
On Monday, December 15, 2003, at 12:53 PM, Rick Anderson wrote:
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])];
}
IIRC, replaceOccurrencesOfString requires 10.2. So if you care about
10.1 compatibility, Karelia source code contains a category of NSString
which is 10.1 compatible.
_______________________________________________
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.