NoviceWithManyProblems Posted January 24, 2020 Share Posted January 24, 2020 local var1 = "Bobby_Bob" --.. local var1.1 = "Bobby" local var1.2 = "Bob" It's possible to do? Link to comment
Moderators Patrick Posted January 24, 2020 Moderators Share Posted January 24, 2020 (edited) local var1 = "Bobby_Bob" local lengthofvar1 = #var1 -- returns: 9 local positionof_ = var1:find("_") -- returns: 6 local first_part = var1:sub(1, positionof_- 1) -- returns: Bobby local second_part = var1:sub(positionof_ + 1, lengthofvar1) -- returns: Bob Edited January 24, 2020 by stPatrick Link to comment
DNL291 Posted January 26, 2020 Share Posted January 26, 2020 Depending on what he wants string.gsub already should do the job. Link to comment
N3xT Posted January 26, 2020 Share Posted January 26, 2020 You can also use: split gettok Link to comment
Enargy, Posted January 26, 2020 Share Posted January 26, 2020 You can use the split function to separate a string into several sub-strings. local sep = "_" -- This character will be your separator local var1 = split("Bobby_Bob", sep) print(var1[1]) -- Result: Bobby print(var1[2]) -- Result: Bob 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