Lua编程示例(四):Lua标准库之表库、字符串库、系统库
tb1 = { "alpha","log","gamme"} print(table.concat(tb1," , ")) print(table.concat(tb1,"\n",nil,2)) print() tb1[88.99] = 'aaa' --返回索引值最大的值,并且计算小数 print(table.maxn(tb1)) print() --默认删除索引最大的元素并返回 print(table.remove(tb1)) print() table.insert(tb1,'3423') table.sort(tb1) print(table.concat(tb1," , ")) function sortFunc(a,b) return a>b end table.sort(tb1,sortFunc) print(table.concat(tb1," , ")) print() print(string.len("")) print(string.len("abcd")) print(string.sub("welcome",1,3)) print(string.sub("welcome",1,-1)) print(string.sub("welcome",1,-5)) print() print(os.date()) print() do local x = os.clock() local s = 0 for i=1,100000000 do s= s+i end print(string.format("the passed time is %.2f\n",os.clock()-x)) end s = "hello world" i, j = string.find(s, "hello") print(i, j) --> 1 5 print(string.sub(s, i, j)) --> hello print(string.find(s, "world")) --> 7 11 i, j = string.find(s, "l") print(i, j) --> 3 3 print(string.find(s, "lll")) --> nil s = string.gsub("Lua is super", "is","makes") print(s) s = string.gsub(s,"a","X") print(s) s = string.gsub(s,"X","a",1) print(s)
运行结果:
alpha , log , gamme alpha log 88.99 gamme 3423 , alpha , log log , alpha , 3423 0 4 wel welcome wel 11/24/11 17:55:44 the passed time is 2.12 1 5 hello 7 11 3 3 nil Lua makes super LuX mXkes super Lua mXkes super
相关推荐
zhuxue 2020-10-14
zhangbingb 2020-09-21
HeronLinuxampARM 2020-09-14
美丽的泡沫 2020-09-08
goodstudy 2020-08-19
luvhl 2020-08-17
littleFatty 2020-08-16
gamestart0 2020-08-15
URML 2020-08-15
sfkong 2020-08-02
82941732 2020-07-27
偏头痛杨 2020-07-18
timewind 2020-07-04
89407707 2020-06-27
xiaoxiaoCNDS 2020-06-26
lyjava 2020-06-26
运算符用于执行程序代码运算,会针对一个以上操作数项目来进行运算。以上实例中 7、5 和 12 是操作数。关系运算符用于计算结果是否为 true 或者 false。逻辑运算符用于测定变量或值之间的逻辑。
ChaITSimpleLove 2020-06-25
Strongding 2020-06-25