'LinKin Posted April 8, 2014 Share Posted April 8, 2014 Hello, How can I separate a string by a certain character. For example if I have SW_GMC_HD_SMTH How can I separate it to indepentent strings like SW, GMC, HD, SMTH. And also, how can I insert them in a table so that I can make a for loop trought it later. Thanks. Link to comment
Saml1er Posted April 8, 2014 Share Posted April 8, 2014 local str = "SW_GMC_HD_SMTH" local str2 = string.gsub (str, "_", "," ) -- replacing underscores with comma -----[[ I'm not sure if gsub works like this since I rarely used this function ]]---- local str3 = split(str2,string.byte(",")) -- splitting it and inserting it into table for _,v in ipairs (str3) do print (v) -- > SW --> GMC --> HD --> SMTH end Not tested. 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