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

Splitting some text to a table, how could I do it?

Hello! I'm trying to make a table that will contain nothing. I want to cut a piece of text, (that's not what I'm asking) and I want to split that string into a table. Example:

table = {}
split(table, text)
print(table)
-- prints: "t", "e", "x", "t"

Thank you so much for any little help!

1 answer

✓ Accepted answer

I can think of two ways to do this.

First, you can just add each character to a table with a simple loop using string.sub.

local function Split(String)
    local Table = {}
    for I = 1, #String do
        table.insert(Table, string.sub(String, I, I))
    end
    return Table
end
Split("Test") -- > {"T", "e", "s", "t"}

Alternatively you could use string.split.

string.split("Test", "") -- > {"T", "e", "s", "t"}

Good luck!

1 comment

0

it does

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