Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make multiple strings out of 1 string?

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?

2 comments

0

use string.sub()

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

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.