Convert formatted string to table of tables

In Lua, is there any way to split this string:

etc3=1336,etc2=14477,etc4=1335,etc1=1337

into this table?

tbl = {
    { 'etc3', 1336 },
    { 'etc2', 14477 },
    { 'etc4', 1335 },
    { 'etc1', 1337 },
}

Any help is appreciated.

Answers


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

Need Your Help

How to join two columns to the same table

mysql sql sql-server

I have an SQL table called messages, it has three columns

How to convert Date to nvarchar

sql-server ibatis

have a search screen and I want to show results by searching specific data.My Filter is "show all date after '7/5/05' date". As this is a JSF form, so 7/5/05 gets stored as Date.And again this is

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.