Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我最近开始摆弄 lua,但我一生都无法弄清楚这一点。
假设我有一个如下所示的字符串:
s = "a=xa=yb=za=x"
我想删除所有重复项并将重复键的值合并到一个表中,这样我得到:
t = { a = {x,y}, b = {z}, }
我一直在思考这个问题太久了。任何帮助表示赞赏!
Try this:
s="a=x a=y b=z a=x" s=s.." " t={} for k,v in s:gmatch("(.-)=(.-)%s+") do if t[k]==nil then t[k]={} end t[k][v]=true end for k,v in pairs(t) do for z in pairs(v) do print(k,z) end end