我在Lua中有一个脚本,我需要打印变量res,但我不知道怎么做这个打印。我在另一个函数中得到函数的结果,我想在那里打印
function parseCSVLine(line)
local res = {}
local pos = 1
local sep = ','
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) -- Digitos
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
例如
local result = parseCSVLine(line)
这里我想打印结果
答案 0 :(得分:3)
Sub exa()
Dim CB As CommandBar
Dim ctl As CommandBarButton
Dim strCBName As String
Dim wbTemp As Workbook
Dim wks As Worksheet
Dim rngInput As Range
Dim i As Long
Set CB = CommandBars.Add(Position:=msoBarPopup, MenuBar:=False, Temporary:=True)
Set ctl = CB.Controls.Add(Type:=msoControlButton, Temporary:=True)
strCBName = CB.Name
'Set wbTemp = Workbooks.Add(xlWBATWorksheet)
'Set wks = wbTemp.Worksheets(1)
Set wks = ThisWorkbook.Worksheets(1)
Set rngInput = wks.Range("A:A")
rngInput.Offset(, -1).ColumnWidth = 6.5
rngInput.ColumnWidth = 6.5
rngInput.HorizontalAlignment = xlRight
For i = 1 To 100
ctl.FaceId = i
ctl.CopyFace
rngInput.Cells(i).PasteSpecial
rngInput.Cells(i).Value = i
Next
rngInput.Cells(1).Select
On Error Resume Next
Set CB = CommandBars(strCBName)
On Error GoTo 0
If Not CB Is Nothing Then
CB.Delete
Else
MsgBox "no toolbar!", 0, vbNullString
End If
End Sub
中的 res
似乎是作为列表创建的。所以试试这个:
parseCSVLine