OpenWrt_Luci_Lua/1_6.lua_test/test_str_foreach.lua
2015-06-13 23:06:56 +08:00

39 lines
821 B
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---------------------Lua遍历字符串的每个字符-----------------------
local s = "hello hi, again"
print(string.len(s))
--[[----failed,expected table, not a string
for i, v in ipairs(s) do
print(v)
end
]]--
--[[success
for i = 0, #s do
print(string.sub(s, i, i))
end
]]--
--------------------------wifi repeat代码--------------------------
local repeat_var_from_http = "1111111"
if string.len(repeat_var_from_http) ~= 7 then
print("len error")
return
end
local week_repeat = ""
for i = 1, #repeat_var_from_http do
tmp = string.sub(repeat_var_from_http, i, i)
if tmp == "1" then
if(i == #repeat_var_from_http) then
week_repeat = week_repeat..0
break
end
week_repeat = week_repeat..tostring(i)..","
end
end
print(week_repeat)