10-07-2019, 10:43 AM
|
#3
|
Human being with feelings
Join Date: May 2018
Location: Los Angeles
Posts: 1,719
|
Quote:
Originally Posted by Lokasenna
That snippet is really only necessary if you need to have commas in the values, i.e. value a, value b, "value c is longer, see?", value d.
I can't test this right now, but try:
Code:
-- CSVs will often have their keys as the first line, in which
-- case you'd have to grab them while reading the file
local csvKeys = {'name', 'someNumber', 'otherNumber'}
local entries = {}
local file, err = io.open("some/file.path", "r")
-- If we had an error, pop up the message and then abort
if err then
reaper.MB(err, "Whoops!", 0)
return
end
for line in file:lines() do
local entry = {}
local i = 1
for val in line:gmatch("[^,]+") do -- matches anything that isn't a comma
entry[csvKeys[i]] = val
i = i + 1
end
entries[#entries + 1] = entry
end
|
Jesus... that was fast!! LOL
Thanks Loka... I'll try it now...
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
|
|
|