Comma-delimited values

Bob Sneidar bobs at twft.com
Mon Mar 8 14:14:18 EST 2010


<sigh> sending again due to the "email too big" problem. 

> I think the operative word in the original post was "might" as in, "might look like this". I gather that it might also not. Is the question, how do you blindly detect a date format? In that case, you are going to need a function that analyzes a string to determine if any of the data between quotes is a date. 
> 
> I might suggest: (as always watch for line wraps)
> 
> on mouseUp pMouseBtnNo
>     put quote & "Mon, Jan 18 , 2010" & quote & ",9:14 AM,130557,4319,Trade,Buy,X,135,8.25,10,-82.5,1417.5,20,10" into myVar
>     set the itemdelimiter to quote
>     repeat for each item theString in myVar
>         if theString is a date then put true -- or whatever else you want to do at this point. 
>     end repeat
> end mouseUp
> 
> Two very obvious problems will immediately present themselves:  First, in the example text given, nothing is a date! Why you ask? Because there is a space in the date after the day number, which is enough to convince Rev that the string is not, in fact, a date. But that may be a typo, and the actual data may correct this anomaly. The second thing is, what if the text has no quotes? 
> 
> All this underscores the fact that you need to understand the nature of the information before you can provide a solution. If it is going to be true CSV, then the dates and all non-numeric data will (or should) be enclosed in quotes.  
> 
> One last caution: When using this form of repeat, remember that you cannot alter the contents of myVar while the loop is running because of the way the repeat command handles the variable. 
> 
> So a revised function that does what you want could look like this: 
> 
> on mouseUp pMouseBtnNo
>     breakpoint
>     put quote & "Mon, Jan 18, 2010" & quote & ",9:14 AM,130557,4319,Trade,Buy,X,135,8.25,10,-82.5,1417.5,20,10" into myVar
>     set the itemdelimiter to quote
>     put myVar into tempVar
>     repeat for each item theString in myVar
>         if theString is a date then
>             put the length of theString into theStrLength
>             put offset(theString, tempVar) into charStart
>             put charStart + theStrLength into charEnd
>             replace comma with "*&*" in char charStart to charEnd of tempVar
>         end if
>     end repeat
>     replace comma with return in tempVar
>     replace "*&*" with comma in tempVar
>     put tempVar into myVar
> end mouseUp
> 
> resulting in data that looks like this:
> 
> "Mon, Jan 18, 2010"
> 9:14 AM
> 130557
> 4319
> Trade
> Buy
> X
> 135
> 8.25
> 10
> -82.5
> 1417.5
> 20
> 10
> 
> Bob
> 
> 
> On Mar 8, 2010, at 9:44 AM, Gregory Lypny 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