RE: [Advice] Inspecting a Plain Text File
RE: [Advice] Inspecting a Plain Text File
- Subject: RE: [Advice] Inspecting a Plain Text File
- From: "Sven Hoffmann" <email@hidden>
- Date: Wed, 9 Mar 2005 19:37:35 +0200
- Thread-topic: [Advice] Inspecting a Plain Text File
The follwing code generates an array of the lineranges of all lines in
the textfile.
You can use the ranges and make an array of the line(string)s or touch
the lines inside the loop.
But i guess you know best what to do with it.
NSString *fileContent = [NSString
stringWithContentsOfFile:textFilePath];
NSMutableArray *lineRanges = [NSMutableArray array];
unsigned int stringIndex = 0;
NSRange thisRange;
unsigned int length = [fileContent length];
while(stringIndex < length){
thisRange = [fileContent
lineRangeForRange:NSMakeRange(stringIndex,0)];
stringIndex = thisRange.location + thisRange.length;
thisRange.length--;
[lineRanges addObject:[NSValue valueWithRange:thisRange]]; }
Hope it helps you...
------------------------------------------------------------------------
------------
Sven Hoffmann
R&D Macintosh Software Develover
Email: email@hidden Tel. 03-6362211
Aladdin Knowledge Systems Ltd.
http://www.aladdin.com
-----Original Message-----
From: cocoa-dev-bounces+sven.hoffmann=email@hidden
[mailto:cocoa-dev-bounces+sven.hoffmann=email@hidden] On
Behalf Of Shawn Erickson
Sent: 09 March, 2005 19:17
To: Andy Satori
Cc: email@hidden
Subject: Re: [Advice] Inspecting a Plain Text File
On Mar 9, 2005, at 9:08 AM, Andy Satori wrote:
> This should do the trick...
>
> NSArray *lineInFile = [[[NSString alloc]
> initWithFile:yourFileName]
> componentsSeparatedByString:@"/n"];
That assume a lot about the line ending and encoding being used in the
text file.
It is better to use NSString's methods...
getLineStart:end:contentsEnd:forRange:
lineRangeForRange:
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
n.com
This email sent to email@hidden
**************************************************************************************************
The contents of this email and any attachments are confidential.
It is intended for the named recipient(s) only.
If you have received this email in error please notify the system manager or the
sender immediately and do not disclose the contents to anyone or make copies.
** eSafe scanned this email for viruses, vandals and malicious content **
**************************************************************************************************
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden