Comma-delimited values

Jeff Massung massung at gmail.com
Mon Mar 8 13:00:53 EST 2010


Couple ideas for you:

Loop over each word in the line and if the word doesn't have quotes, replace
comma with tab:

repeat with tWord = 1 to the number of words in tLine
   if the first char of word tWord in tLine is not quote then
      replace comma with tab in word tWord of tLine
   end if
end repeat

Use a regex or another search function to find quotes and skip over them,
replacing commas with tabs with for everything in between.

If you have access to the input data (read: from a db query or some-such),
just modify it at the source.

If your quoted data is always dates you could change the dates to something
else. For example:

repeat with tIdx = 1 to the number of words in tLine
   if word tIdx of tLine is a date then
      convert word tIdx of tLine to seconds
   end if
end repeat

And now you can do other kinds of operations on the date or even convert
them back to dates later on.

I wouldn't try doing anything goofy like trying to change commas within
quotes to something else and then change them back. It'll lead to bugs later
on I'm quite sure.

This is the one thing about Rev I wish I could change... quotes should wrap
items just as they wrap words.

Jeff M.

On Mon, Mar 8, 2010 at 11:44 AM, Gregory Lypny
<gregory.lypny at videotron.ca>wrote:

> Hello everyone,
>
> I'm creating an app that imports comma-delimited tables.  A few lines might
> look like this, where there are 14 items per line.
>
> "Mon, Jan 18 , 2010",9:14
> AM,130557,4319,Trade,Buy,X,135,8.25,10,-82.5,1417.5,20,10
> "Mon, Jan 18 , 2010",9:14 AM,130558,4371,Accept,Your
> ASK,X,135,8.25,10,82.5,1582.5,0,10
>
> My problem is that Rev treats each date in quotes as three items rather
> than one.  I convert the comma delimiters to tab by setting the
> itemDelimiter to comma and then running the lines through nested
> repeat-for-each loops as
>
> repeat for each line thisLine in dataTable
> repeat for each item thisItem in thisLine
> put thisItem & tab after newLine
> end repeat
> -- more stuff here
> end repeat
>
> I end up with
>
> "Mon    (as the first item)
> Jan 18  (as the second)
> 2010"   (as the third)
>
> Any suggestions as how I might get the date treated as one item?
>
> Regards,
>
>        Gregory
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>



More information about the use-livecode mailing list