• 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: jerome LAURENS <email@hidden>
  • Date: Sat, 25 May 2002 01:23:01 +0200

Le vendredi 24 mai 2002, ` 08:31 PM, Andreas Mayer a icrit :

> 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 ...
>

This one might be close to the best, next step should be to bypass the
objc message calls but I doubt it will be so efficient, except for very
very very long texts

- (void)splitLines:(NSString *)string
{
unsigned stringLength = [string length];
NSRange lineRange = NSMakeRange(0, 0);
NSRange searchRange = NSMakeRange(0, 0);

while (searchRange.location<stringLength)
{
[string getLineStart: nil end:&searchRange.location
contentsEnd:nil forRange: searchRange];
lineRange.length = searchRange.location - lineRange.location;
[arrayOfLines addObject:[string substringWithRange: lineRange]];
lineRange.location = searchRange.location;
}
}
_______________________________________________
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.

References: 
 >Re: scannerWithString (From: Andreas Mayer <email@hidden>)

  • Prev by Date: Re: Build product size
  • Next by Date: Re: [OT] Re: Constructive Ideas
  • Previous by thread: Re: scannerWithString
  • Next by thread: Build product size
  • Index(es):
    • Date
    • Thread