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 中,有没有办法拆分这个字符串:
etc3=1336,etc2=14477,etc4=1335,etc1=1337
进这张表?
tbl = { { 'etc3', 1336 }, { 'etc2', 14477 }, { 'etc4', 1335 }, { 'etc1', 1337 }, }
任何帮助表示赞赏。
local str = 'etc3=1336,etc2=14477,etc4=1335,etc1=1337' local tbl = {} for k, v in str:gmatch'(%w+)=(%d+)' do tbl[#tbl+1] = {k, tonumber(v)} end