• 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: CsvToListOfText
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CsvToListOfText


  • Subject: Re: CsvToListOfText
  • From: T&B <email@hidden>
  • Date: Fri, 15 Dec 2006 11:21:41 +1100

Hi Roger,

You and Emmanuel have explained why the displayed results looked different because I had rather emphasised that aspect but what I should have emphasised was that the results (contents) were different.

The difference in the content is that the output is Smile is one long "row". Where the Script Editor output shows the beginning of a new row, the Smile output instead shows what should be the last item of the previous row and the first item of the next row joined together with a return between them.


This is to be expected, since you're asking Smile to parse the text with a new row when it finds a linefeed, but the raw text that you're giving (in Smile) has no linefeeds, only returns.

So, what you need to do is change the way that you call the CsvToListOfText routine. If the text contains linefeeds (such as text typed into Script Editor), you do this:

property linefeed : ASCII character 10

set newLineString to linefeed

CsvToListOfText(csvText, separatorString, quoteString, newLineString)

But if your text contains returns (such as text typed or pasted into Smile), you'd do this:


set newLineString to return

CsvToListOfText(csvText, separatorString, quoteString, newLineString)

and it will give the same result.

Or you can do this to make it work for line ending of return, linefeed or CR/LF (return & linefeed):

set newLineString to GetLineEnding(csvText)

CsvToListOfText(csvText, separatorString, quoteString, newLineString)

on GetLineEnding(textSample)
   set foundLineEnding to null
   repeat with lineEndingRef in {return & linefeed, linefeed, return}
      set myLineEnding to contents of lineEndingRef
      if textSample contains myLineEnding then
         set foundLineEnding to myLineEnding
         exit repeat
      end if
   end repeat
   return foundLineEnding
end GetLineEnding

But sometimes the line ending is even more complex, such as SQL INSERT statements, so having a newLineString argument in the function gives us flexibility to handle anything.

I hope this explains it better :-)

Tom

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: CsvToListOfText
      • From: R Morris <email@hidden>
References: 
 >Re: Importing/parsing CSV files (From: T&B <email@hidden>)
 >CsvToListOfText (From: T&B <email@hidden>)
 >Re: CsvToListOfText (From: R Morris <email@hidden>)
 >Re: CsvToListOfText (From: T&B <email@hidden>)
 >Re: CsvToListOfText (From: R Morris <email@hidden>)

  • Prev by Date: Moving files to another user
  • Next by Date: Re: awk question
  • Previous by thread: Re: CsvToListOfText
  • Next by thread: Re: CsvToListOfText
  • Index(es):
    • Date
    • Thread