"./test.lua" 31L, 565C 已写入
ghost@debian:~$ vim ./test.lua
#!/usr/local/bin/lua
str = [[123456,["Partner"]={[1]="1", [2]="2"}["Friend"] = {[1] = "123"}]]
--str_start = '\["Partner"\]'
--str_end = '\["Friend"\]'
print("str", str)
b1, e1 = string.find(str, ".\"Partner\".")
b2, e2 = string.find(str, ".\"Friend\".")
print(b1, e1)
print(b2, e2)
str_sub = string.sub(str, e1 + 2, b2 -1)
print("str_sub:", str_sub)
function Print_tbl(_Tbl)
if type({}) == type(_Tbl) then
for k, v in pairs(_Tbl) do
Print_tbl(v)
end
else
print(_Tbl)
end
end
luavalue = loadstring("return ".. str_sub)()
Print_tbl(luavalue)
结果输出是1,2
loadstring可以将字符串变成一个table