Page 1 of 1
CSV Processing
Posted: Fri Jul 10, 2009 5:25 am
by ivanw
I'm hitting an issue when parsing csv data - searched the forum but could not find an answer.
Basically I'm doing a item loop to extract csv data.
However my csv data is itself separated by single quotes.
e.g. when I loop over this with a "for each item":
I get:
Does anyone know if Rev has item processing so I can instead get this?
Thanks!
Ivan
CSV processing
Posted: Fri Jul 10, 2009 7:55 am
by jmburnod
Ivan,
You can change the itemdelimiter.
Jean-Marc
Posted: Fri Jul 10, 2009 8:05 am
by ivanw
Hi Jean Marc,
Sorry I think I didn't explain clearly.
My data is actually comma delimited, but some items have a non-delimiting comma, and these items are identified by single quotes:
e.g. '100,000' is actually one item and not two as the comma should not be recognized as an item delimiter.
I was wondering if the item processing could take account of that.
I think I will have to code a workaround.
Thanks anyway,
Ivan
Posted: Fri Jul 10, 2009 8:44 am
by Mark
Hi Ivan and Jean-Marc,
Try the following function:
Code: Select all
function csv2tsv theData,theRemoveQuote
replace comma with tab in theData
replace "'" with quote in theData
put number of words of theData
repeat for each line myLine in theData
repeat for each word myWord in myLine
if myWord contains tab then replace tab with comma in myWord
put myWord & tab after myNewData
end repeat
delete last char of myNewData
put cr after myNewData
end repeat
if theRemoveQuote is true then replace quote with empty in myNewData
return myNewData
end csv2tsv
This function converts your comma-delimited data to tab-delimited data. If theRemoveQuote is true, it also removes the quotes.
Best regards,
Mark
CSV processing
Posted: Fri Jul 10, 2009 9:42 am
by jmburnod
Yes Mark
Your csv2tsv function work
Best regards
Jean-Marc
Posted: Fri Jul 10, 2009 5:40 pm
by ivanw
Thank you Mark & Jean-Marc,
I've learnt something new about word processing and quotes in Rev.
Ivan