首页 > 开发 > 综合 > 正文

Lua编程示例(四):Lua标准库之表库、字符串库、系统库

2024-07-21 23:04:59
字体:
来源:转载
供稿:网友
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>bendtable.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))ends = "hello world"i, j = string.find(s, "hello")print(i, j)    --> 1  5print(string.sub(s, i, j))  --> helloprint(string.find(s, "world"))  --> 7  11i, j = string.find(s, "l")print(i, j)    --> 3  3print(string.find(s, "lll"))  --> nils = 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 , gammealphalog88.99gamme3423 , alpha , loglog , alpha , 342304welwelcomewel11/24/11 17:55:44the passed time is 2.121 5hello7 113 3nilLua makes superLuX mXkes superLua mXkes super

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表