Skip to content

thenumbernine/lua-csv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

Donate via Stripe
Donate via Bitcoin

CSV parser for Lua

Examples:

Reading CSV data:

local CSV = require 'csv'
local d = CSV.file(filename)	-- read data from file
local d = CSV.string(string)	-- read data from string

Accessing data by row/column indexes:

print(d.rows[i])	-- access the i'th row
print(d.rows[i][j])	-- access the j'th column of the i'th row

Accessing data by named columns:

local names = {'id', 'rank', 'etc'}
d:setColumnNames(names) -- sets column names, then you can do this:
d.rows[1].rank			-- gets you cell 1,1

Setting field names to the first comment line:

local string = require 'ext.string'
d:setColumnNames(string.split(d.comments[1],','))

Setting field names to the first row:

d:setColumnNames(d.rows:remove(1))

Dependencies:

About

CSV parser in Lua

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages