NoviceWithManyProblems Posted January 24, 2020 Posted January 24, 2020 local var1 = "Bobby_Bob" --.. local var1.1 = "Bobby" local var1.2 = "Bob" It's possible to do?
Moderators Patrick Posted January 24, 2020 Moderators 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
DNL291 Posted January 26, 2020 Posted January 26, 2020 Depending on what he wants string.gsub already should do the job.
Enargy, Posted January 26, 2020 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
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