Re: Parsing a simple text file, row per row (*solved*)
Re: Parsing a simple text file, row per row (*solved*)
- Subject: Re: Parsing a simple text file, row per row (*solved*)
- From: BK <email@hidden>
- Date: Tue, 2 Aug 2005 05:34:35 +0900
On Aug 2, 2005, at 2:50, Frederick C. Lee wrote:
NSArray *acRawRows = [acDataString
componentsSeparatedByString:@"\n"]; <-- doesn't see "\n"
(apparently).
It turns out that I had the text file saved in Mac vs Unix format. So
the line breaks use CR vs NL. So the correct delimiter is '\r' and
not '\n'.
...Sigh; just more to remember.
You may want to check out our StringOps library, especially this method
...
//
------------------------------------------------------------------------
---
// Instance Method: arrayBySeparatingLinesUsingEOLmarkers
//
------------------------------------------------------------------------
---
//
// pre-conditions:
// the receiver is an NSString, it may be an empty string.
//
// post-conditions:
// if the receiver is an empty string, an empty array will be returned.
// if there are no EOL markers present in the receiver, an array with a
// single object containing a copy of the receiver will be returned.
// otherwise, an array with the number of member objects equal to the
number
// of lines in the receiver is returned with each object containing
one line
// in the same order as they appear in the receiver. the EOL markers
used to
// determine the end of a line are Line Feed (U+000A) and Carriage
Return
// (U+000D). The EOL marker sequence CRLF (U+000D followed by U+000A)
is
// treated as a single EOL marker.
//
// error-conditions:
// if the receiver is nil, nil is returned.
- (NSArray *)arrayBySeparatingLinesUsingEOLmarkers;
which does recognise CR, LF and CRLF, so you won't have to worry about
what line feed format the file is actually using.
The StringOps library is included in the STS Template Engine which you
can download here ...
http;//www.sunrise-tel.com/STSTemplateEngine.html
The Template Engine is GPL and dual licensed BUT the StringOps library
is BSD licensed. There are other methods in there which you may find
useful for your text parsing reuirement.
rgds
bk _______________________________________________
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