• 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: Parsing a simple text file, row per row (*solved*)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Parsing a simple text file, row per row (*solved*) (From: "Frederick C. Lee" <email@hidden>)

  • Prev by Date: Re: Sending messages to nil on Intel
  • Next by Date: Re: Vu-meter
  • Previous by thread: Parsing a simple text file, row per row (*solved*)
  • Next by thread: Re: NSDateFormatter
  • Index(es):
    • Date
    • Thread