【发布时间】:2016-03-16 04:40:12
【问题描述】:
我是 lua 新手,我正在尝试从拆分字符串的右侧提取值。我有这个:
local t ={}
local data = ("ret=OK,type=aircon,reg=eu,dst=1,ver=2_2_5,pow=1,err=0,location=0,name=,icon=0,method=home only,port=30050,id=,pw=,lpw_flag=0,adp_kind=2,pv=0,cpv=0,led=1,en_setzone=1,mac=FCDBB382E70B,adp_mode=run")
for word in string.gmatch(data, '([^,]+)') do
t[#t + 1] = word
end
local first = t[1]:gsub("%s+", "")
这给了我字符串“ret=OK”。 我该怎么做才能从这个字符串中只得到“OK”,比如:从等号右侧获取所有内容并将其和左侧部分删除。我必须对“数据”变量中的所有字符串执行此操作。谢谢。
【问题讨论】:
-
这几乎是来自
string.gmatch的lua手册部分的示例。