Is there an way to split an string and save it into an table like this:
str = "23 = John, 45 = Karl, 6 = Chloe, 34 = Sarah"
--[[ 23 John
45 Karl
6 Chloe
34 Sarah]]
I want the numbers to be the keys and the Names to be the values.
CodePudding user response:
Adapt this code:
for k,v in str:gmatch("(%d )%s*=%s*(%a )") do
print(k,v)
end
This assumes that the names are composed of letters only.