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

How to separate words in a string?

Lets say I have this string

local string = "Hello Im a toaster"

How would I be able to only get the second word of that string?

The string will be different each time and that is just an example

For Example

print(string[2])

and it would output "Im"

I know that's not how you do it buy I hope you get the point

1 answer

✓ Accepted answer

Roblox has specially implemented a string split method to take out pieces in a string.

Here's a quick example:

local str = "it's a beautiful day outside"

local words = str:split(" ")
print(words[1]) --> "it's"

2 comments

0

Could str:split("") work to seperate even letters?

0

that may work, try it

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