字符串查找 返回相匹配的起始位置和结束位置
local str = "1111234asdfzxa";
local a,b = string.find(str,"1234");
print(a,b);
字符串变大写
a = string.upper( str );
print(a);
方法可变参数
function average(...)
result = 0;
tb4 = {...}
for i = 1, #tb4 do
result = result + tb4[i];
end
print(result);
end
average(1,2,3,4);
ipairs与pairs ipairs遇到nil跳出, pairs遇到nil跳过,继续往后执行.pairs如果遇到有键值的会无序遍历,标准table会有序遍历。
function average(...)
result = 0;
tb4 = {...}
table.insert(tb4,"str");
for i,v in ipairs(tb4) do
print(v);
end
for k, v in pairs(tb4) do
print(v);
end
end
average(1,2,3,nil,4);
输出结果:
1 1 2 2 3 3 1 1 2 2 3 3 5 4 6 str
math随机函数
math.randomseed( os.time() );
for i = 1, 10 do
print(math.random(1,100));
end