Re: scannerWithString
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.