• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Remove excess line breaks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Remove excess line breaks


  • Subject: Re: Remove excess line breaks
  • From: Jens Bauer <email@hidden>
  • Date: Mon, 15 Dec 2003 13:22:25 +0100

Hi Rick,

Try looking at the NSString snippet on <URL:http://objc-source.com/>

On Monday, Dec 15, 2003, at 12:53 Europe/Copenhagen, 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])];
}


Love,
Jens
_______________________________________________
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.

  • Follow-Ups:
    • Re: Remove excess line breaks
      • From: p3consulting <email@hidden>
References: 
 >Remove excess line breaks (From: Rick Anderson <email@hidden>)

  • Prev by Date: Remove excess line breaks
  • Next by Date: Re: Remove excess line breaks
  • Previous by thread: Remove excess line breaks
  • Next by thread: Re: Remove excess line breaks
  • Index(es):
    • Date
    • Thread