• 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 02:02:06 +1100

Hi Roger,

That's interesting.

I tried the script below

1. with Script Editor (Version 2.1.1 (81) AppleScript 1.10.7) I get (in the Result window)

{{"item1", "item2", "NULL", "item4"}, {"item5", "item6", "NULL", "item'7'"}, {"item9", "item10", ""}, {"item11", "", "item13"}, {"", "item15", "item16", "", "item18"}}

2.  with Smile 3.2.0b (build 344) I get (in the Console window)

{{"item1", "item2", "NULL", "item4
item5", "item6", "NULL", "item'7'
item9", "item10", "
item11", "", "item13
", "item15", "item16", "", "item18"}}

As Emmanuel pointed out, pasting my sample csvText string into your script editor will assume whatever new line character that editor uses. It's similar to how real CSV files you might read into the script may be use different new line characters. But that's fine, as long as you define the new line character(s) for the CsvToListOfText script to use. I made newLineString an argument for the function for that reason.


So you don't need to change the CsvToListOfText routine at all, but just change the arguments that you submit to it. So where I had, in the sample:

set newLineString to linefeed

CsvToListOfText(csvText, separatorString, quoteString, newLineString)

you'd simply change the newLineString to:

set newLineString to return

You could even use a routine to figure out what new line character is used, such as:

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

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>)

  • Prev by Date: Re: ctrl m question
  • Next by Date: Re: awk question
  • Previous by thread: Re: CsvToListOfText
  • Next by thread: Re: CsvToListOfText
  • Index(es):
    • Date
    • Thread