Jump to content

Separate strings


'LinKin

Recommended Posts

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
  
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...