<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.hoodedhorse.com/Against_the_Storm/index.php?action=history&amp;feed=atom&amp;title=Module%3AParseCSV</id>
	<title>Module:ParseCSV - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.hoodedhorse.com/Against_the_Storm/index.php?action=history&amp;feed=atom&amp;title=Module%3AParseCSV"/>
	<link rel="alternate" type="text/html" href="https://wiki.hoodedhorse.com/Against_the_Storm/index.php?title=Module:ParseCSV&amp;action=history"/>
	<updated>2026-10-18T12:15:37Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.5</generator>
	<entry>
		<id>https://wiki.hoodedhorse.com/Against_the_Storm/index.php?title=Module:ParseCSV&amp;diff=2112&amp;oldid=prev</id>
		<title>76561197969631737: Created so we can upload the CSV data (like into Module:GoodsCSV and others) and parse it automatically</title>
		<link rel="alternate" type="text/html" href="https://wiki.hoodedhorse.com/Against_the_Storm/index.php?title=Module:ParseCSV&amp;diff=2112&amp;oldid=prev"/>
		<updated>2023-06-10T16:30:26Z</updated>

		<summary type="html">&lt;p&gt;Created so we can upload the CSV data (like into Module:GoodsCSV and others) and parse it automatically&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--- Module for parsing CSV data into a Lua table.&lt;br /&gt;
-- @module ParseCSV&lt;br /&gt;
local ParseCSV = {}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--- Parses the CSV data and returns the header and rows as a Lua table.&lt;br /&gt;
-- @tparam string csvString The CSV data to be parsed.&lt;br /&gt;
-- @treturn table The header of the CSV data.&lt;br /&gt;
-- @treturn table The rows of the CSV data.&lt;br /&gt;
function ParseCSV.parseCSV(csvString)&lt;br /&gt;
&lt;br /&gt;
    -- Check for an end-of-file comma&lt;br /&gt;
    if csvString:sub(-1) == &amp;#039;,&amp;#039; then&lt;br /&gt;
        csvString = csvString:sub(1, -2) -- Remove the trailing comma&lt;br /&gt;
    end&lt;br /&gt;
	&lt;br /&gt;
    local header = nil&lt;br /&gt;
    local rows = {}&lt;br /&gt;
&lt;br /&gt;
    -- Separate the csv data into lines/rows by gmatch&amp;#039;ing on carriage returns &lt;br /&gt;
	-- and/or newlines&lt;br /&gt;
    for line in csvString:gmatch(&amp;quot;[^\r\n]+&amp;quot;) do&lt;br /&gt;
        &lt;br /&gt;
		-- the first line will be the header, after we build it, everything else&lt;br /&gt;
		-- goes into the rows table&lt;br /&gt;
		if not header then&lt;br /&gt;
		&lt;br /&gt;
			-- we started with nil, so replace nil with a blank table&lt;br /&gt;
            header = {}&lt;br /&gt;
&lt;br /&gt;
			-- Separate the rows into fields by gmatch&amp;#039;ing on commas&lt;br /&gt;
			for field in line:gmatch(&amp;quot;[^,]+&amp;quot;) do&lt;br /&gt;
				-- append the last-matched field (value) to the header table&lt;br /&gt;
				table.insert(header, field)&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			-- there is only one row in the header table, so we don&amp;#039;t need to do&lt;br /&gt;
			-- anything else&lt;br /&gt;
			&lt;br /&gt;
		else&lt;br /&gt;
			-- build each line separately as a new table&lt;br /&gt;
            local row = {}&lt;br /&gt;
			&lt;br /&gt;
            for field in line:gmatch(&amp;quot;[^,]+&amp;quot;) do&lt;br /&gt;
				-- append the last-matched field (value) to the row table&lt;br /&gt;
                table.insert(row, field)&lt;br /&gt;
            end&lt;br /&gt;
			&lt;br /&gt;
			--append the constructed row to the rows table&lt;br /&gt;
            table.insert(rows, row)&lt;br /&gt;
        end&lt;br /&gt;
		&lt;br /&gt;
    end -- for each line&lt;br /&gt;
&lt;br /&gt;
    -- Return the header and the rows data table&lt;br /&gt;
    return header, rows&lt;br /&gt;
	&lt;br /&gt;
end -- parseCSV function&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
return ParseCSV&lt;/div&gt;</summary>
		<author><name>76561197969631737</name></author>
	</entry>
</feed>