Dychuk Posted July 28, 2018 Share Posted July 28, 2018 Hi, all! I have string "{100}Hello, world! {45}How are you?". How I can this string split into two arrays with parameters, i.e. in the end I got array: ar = { {100, "Hello, world! "}, {45, "How are you?"} } I make script: ar = {} s = "{100}Hello, world! {45}How are you?" for k, v in string.gmatch(s, "({%d+})(%w+)") do table.insert(ar, {k, v}) end for k,v in ipairs(ar) do outputChatBox("K: " .. k .. " V1: " ..v[1] .. " V2: " .. v[2]) end as a result, I received K: 1 V1: {100} V2: Hello K: 2 V1: {45} V2: How but that's not what I need but I need this K: 1 V1: 100 V2: Hello, world! K: 2 V1: 45 V2: How are you? Help me, please p.s. sorry for bad english Link to comment
Rockyz Posted July 28, 2018 Share Posted July 28, 2018 (edited) maybe something like this ? ar = {} s = '{100}Hello, world!{end}{45}How are you?{end}' for k, v in string.gmatch(s, '{(%d+)}(.-){end}') do table.insert(ar, {k, v}) end for k,v in ipairs(ar) do outputChatBox('K: ' .. k .. ' V1: ' ..v[1] .. ' V2: ' .. v[2]) end Edited July 28, 2018 by #,+( _xiRoc[K]; > Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now