• 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: scannerWithString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scannerWithString


  • Subject: Re: scannerWithString
  • From: Andreas Mayer <email@hidden>
  • Date: Fri, 24 May 2002 20:31:04 +0200

Am Freitag den, 24. Mai 2002, um 12:47, schrieb Frank Blome:

Is this the right approach? Or will there be a better way?

This is exactly what I did a few days ago. So here is my code:


NSMutableArray *arrayOfLines = [[NSMutableArray array] retain];

- (void)splitLines:(NSString *)string
{
unsigned start;
unsigned end;
unsigned next;
unsigned stringLength;
NSRange range;

stringLength = [string length];
range.location = 0;
range.length = 1;
do {
[string getLineStart:&start end:&next contentsEnd:&end forRange:range];
range.location = start;
range.length = end-start;
[arrayOfLines addObject:[string substringWithRange:range]];
range.location = next;
range.length = 1;
} while (next < stringLength);
}

But there may very well be a better way ...

(You could use NSMakeRange() instead of assigning location and length seperately, but that would probably be somewhat slower, since it would create a new NSRange struct with every call.)


bye. Andreas.
_______________________________________________
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: scannerWithString
      • From: jerome LAURENS <email@hidden>
References: 
 >scannerWithString (From: Frank Blome <email@hidden>)

  • Prev by Date: Accessor Madness
  • Next by Date: Re: C++ Strings Handling
  • Previous by thread: scannerWithString
  • Next by thread: Re: scannerWithString
  • Index(es):
    • Date
    • Thread