access to the different cols of a csv file
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
access to the different cols of a csv file
hi,
can anybody tell me how i can have access to the different cols of a tabsepareted csv file ?
i know how to read the file and store the lines in an array. but i can not find a way to get
a specific col (or field) of the lines.
thank you for your help.
kind regards.
fre
can anybody tell me how i can have access to the different cols of a tabsepareted csv file ?
i know how to read the file and store the lines in an array. but i can not find a way to get
a specific col (or field) of the lines.
thank you for your help.
kind regards.
fre
Re: access to the different cols of a csv file
Your best bet is to read in the CSV file and save it to a multi-dimensional array and then loop over that..
Re: access to the different cols of a csv file
thanks shaosean, that is exactly what i want to do.
the problem is: i do not know how to.
what i need is something like php's explode function,
because after reading the csv file i have lines that are strings
and every string has data in it, separated by tabs.
i find it hard to find the code i need in the LiveCode dictionary.
there are hundreds of commands and functions, do i have to study the whole dic to find what i need?
what i miss, is that this dic does not tell me e.g. all the string functions, all the array function, ...
does anybody know if there is something like the php explode function in LiveCode ?
thank you and best regards.
fre.
the problem is: i do not know how to.
what i need is something like php's explode function,
because after reading the csv file i have lines that are strings
and every string has data in it, separated by tabs.
i find it hard to find the code i need in the LiveCode dictionary.
there are hundreds of commands and functions, do i have to study the whole dic to find what i need?
what i miss, is that this dic does not tell me e.g. all the string functions, all the array function, ...
does anybody know if there is something like the php explode function in LiveCode ?
thank you and best regards.
fre.
Re: access to the different cols of a csv file
Hi Fre,
This script might be useful to convert your CSV into into tab-delimited data. After running this script, you can do the following...
(Mind typos and line wraps; this script is untested).
First read your file into a variable, then execute the function that's on my blog and finally execute above part of the script.
Best regards,
Mark
This script might be useful to convert your CSV into into tab-delimited data. After running this script, you can do the following...
Code: Select all
// Assume that myData contains all data.
// For the occasion, assume that gDataArray is a global variable.
// line 1 contains column titles
// first line of each line is a label
set the itemDel to tab
put line 1 of myData into myTitles
// item 1 should be empty or irrelevant
delete item 1 of myTitles
delete line 1 of myData
put 1 into myItemCounter
repeat for each item in myTitles
add 1 to myItemCounter
put 0 into myLineCounter
repeat for each line in myData
add 1 to myLineCounter
put item myItemCounter of line myLineCounter into gDataArray[item myItemCounter of myTitles][item 1 of line myLineCounter of myData]
end repeat
end repeat
First read your file into a variable, then execute the function that's on my blog and finally execute above part of the script.
Best regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: access to the different cols of a csv file
There is the split command, not certain if it handles multi-dimensional arrays though..
Re: access to the different cols of a csv file
Hi Shaosean,
Unfortunately, the split command doesn't help in this case.
Kind regards,
Mark
Unfortunately, the split command doesn't help in this case.
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: access to the different cols of a csv file
thank you for your help !
best regards
fre
best regards
fre