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

Iterate through a string's text?

If I have a string is it possible to iterate the each character in the string and print it one at a time?

For instance:

I have a string as a variable local message = "Welcome"

Now I want it to print.

 "W"
 "E"
 "L"
 "C"
 "O"
 "M"
 "E"

Instead of printing, "Welcome"

How would I do this?

Edit: Moved some text to a code block to preserve formatting.

1 comment

0

I figured it out but will still accept the first correct answer.

1 answer

✓ Accepted answer

An easy application of gmatch will allow you to do this. Just use "(%w)" as the string pattern

EX

for w in string.gmatch("Pizza", "(%w)") do -- 'w' represents the individual letter returned
    print(w)
end

3 comments

1

Replace "Pizza" with "Welcome" if you aren't hungry

1

Use "." instead of "%w" if you want to include other kinds of characters (like spaces and punctuation) in the iteration

0

Good point

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