Ich möchte die Lua CSV http://lua-users.org/wiki/LuaCsv verwenden und benötigen eine der Spalten aufgeteilt, die einen Bindestrich „-“ zum Beispiel: Erste-Name in der Tabelle es schafft. Ich kann es manuell in Excel mit Daten> Text zu Spalten, die die Full-Name-Zelle teilen und fügen Sie eine erste und eine Nachname Spalte bis zum Ende, ich brauche Lua, um das gleiche im Skript zu tun:Lua - Split CSV Säule bei Hyphen
Before
Age,Name,Start,End,Length,Score
35,Bill-Smith,2.2.2017,2.4.2017,0.2.00,2056
After
Age,Name,Start,End,Length,Score,First,Surname
35,Bill-Smith,2.2.2017,2.4.2017,0.2.00,2056,Bill,Smith
Dies wird LUA CSV-Parser eingesetzt werden:
function ParseCSVLine (line,sep)
local res = {}
local pos = 1
sep = sep or ','
while true do
local c = string.sub(line,pos,pos)
if (c == "") then break end
if (c == '"') then
-- quoted value (ignore separator within)
local txt = ""
repeat
local startp,endp = string.find(line,'^%b""',pos)
txt = txt..string.sub(line,startp+1,endp-1)
pos = endp + 1
c = string.sub(line,pos,pos)
if (c == '"') then txt = txt..'"' end
-- check first char AFTER quoted string, if it is another
-- quoted string without separator, then append it
-- this is the way to "escape" the quote char in a quote. example:
-- value1,"blub""blip""boing",value3 will result in blub"blip"boing for the middle
until (c ~= '"')
table.insert(res,txt)
assert(c == sep or c == "")
pos = pos + 1
else
-- no quotes used, just look for the first separator
local startp,endp = string.find(line,sep,pos)
if (startp) then
table.insert(res,string.sub(line,pos,startp-1))
pos = endp + 1
else
-- no separator found -> use rest of string and terminate
table.insert(res,string.sub(line,pos))
break
end
end
end
return res
end
Was ist Ihre Frage? – Piglet
Was Ferkel gesagt hat. Es ist nicht klar, was genau dein Problem ist. –
Die CSVs haben einen Namensstring mit einem - in der Mitte. Ich brauche Lua, um diese Zelle am Bindestrich zu teilen und sie zu zwei neuen Zellen in der Tabelle hinzuzufügen. https://support.office.com/de-de/article/Split-text-into-different-columns-with-the-Convert-Text-in-Columns-Wizard-30B14928-5550-41F5-97CA-7A3E9C363ED7 – LuaStart