• Strip matching special patterns in string?
    2 replies, posted
I have a value within a database which is formatted as much ["item1","item2","item_3"] I've looked into gsub, trim (which I see is for spaces only I assume from what I read), and a few other things on the garry's mod wiki, but they aren't returning the desired output. I want to strip the special characters from the string, replace commas with spaces, and if an underscore exists (as some will have one), it simply leaves it intact so that the result would be: item1 item2 item_3 for LUA. Any suggestions would be greatly appreciated. I tried patterns and looked at the list, but I can't seem to make the right pattern to do this or the result is "nil".
Err. If your data actually has format like [i]["item1","item2","item_3"][/i] then just pass it through util.JSONToTable and use table.concat: [code] local data = '["item1","item2","item_3"]' data = table.concat(util.JSONToTable(data), " ") print(data) -- Output: -- item1 item2 item_3 [/code] Is that what you want to do?
You sir, are amazing. The output is exactly what I needed. And I was sitting here strapping my brain around patterns. Never thought to look at concat as I haven't experimented with it before. Thanks a bunch.
Sorry, you need to Log In to post a reply to this thread.