Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make multiple strings out of 1 string?

Asked by 5 years ago
Edited 5 years ago

hi guys!

i'm trying to do something, but i am not sure how to do it. so basically, i have this string:

Username:true:Another Thing

I want to split it into 3 different strings: - Username - True (and make it a bool) - Another Thing

does anyone know how to do this?

0
use `string.sub()` Is_Hunter 152 — 5y
0
yea but how would i use it to split it where there's a ":"? in what i see the only thing string.sub() does is cut it off with numbers, not by saying cut when this character is in it RazerGamingKeyboard 17 — 5y

1 answer

Log in to vote
0
Answered by
Isaque232 171
5 years ago
Edited 5 years ago

You can use the function string.gmatch to solve your issue, I suggest for you to take a look at the String library and String Pattern as those will definitely help you with some string issues, at this case you could use this code for example to separate each string when there's an " : " on it.

local TheString = "Username:true:Another Thing" -- Your string

for i in string.gmatch(TheString,  "[^:]+") do -- Separates the string when it reaches " : "
    print(i)
end

In this case it would make 3 different strings and out would output:

"Username" "true" "Another Thing"

Hopefully this helps you with your issue! Don't forget to accept it if it did solve it.

Ad

Answer this question