Some common string operations are recorded below
Local STR = "Hello World" -- string. len can obtain the string length: Local Len = string. len (STR) print (LEN) -- string. rep returns the result STR = "AB" Local newstr = string. rep (STR, 2) print (newstr) -- string. lower converts the string to uppercase in lower case and returns a new copy str1 = "Shenqi" newstr = string. lower (str1) print (newstr) -- string. upper converts the string to lowercase in uppercase and returns a new copy str2 = "Shenqi" newstr = string. upper (str2) print (newstr)
Get Time Operation
Local tbcurrenttime = OS. date ("* t") for K, V in pairs (tbcurrenttime) Do print (K .. "=" .. tostring (V) End
Local STR = "Hello World" Local I, j = string. find (STR, "hello") print (I, j) -- 1 5str = "hello876323124world" Local I, j = string. find (STR, "% d +") print (I, j) -- 6 14 local substr = string. match (STR, "% d +") print (substr) -- 876323124 local I, j = string. find (STR, "% d +") substr = string. sub (STR, I, j) print (substr) -- 876323124
Replace
Local STR = "Hello World" -- the replacement times are not limited here. Local strresult, CNT = string. gsub (STR, "L", "O") print (strresult) print (CNT) -- start to limit the number of replicas strresult, CNT = string. gsub (STR, "L", "O", 1) print (strresult) print (CNT)
Address: http://blog.csdn.net/qqmcy/article/details/39180391
Lua basic string operations