lua笔记之字符串分割,table长度计算.md

例子如下:

local d = "bp,99999999999999999999999,2018/09/09,12:08,128,092,077,062,0";
local value = {};
v, count = string.gsub( d, '[^,]+', function(w) table.insert( value, w ) end  );

print( count ); //长度
print( #value ); //长度

print( value[2] ); // 999999999999.....
 

lua 出现 xxx: attempt to call a nil value (field ‘getn’) 解决办法

lua 在5.1以后不再使用table.getn( param )获取table的长度.

改为 #param

例子如下:

local mytable = {1,2,3};
table.getn(mytable)
stdin:1: attempt to call a nil value (field 'getn')
stack traceback:
    stdin:1: in main chunk
    [C]: in ?
local count = #mytable;