How to convert string to table?

I basically want to replicate the behavior we would see in C where strings are basically arrays. So suppose I had “Tree” that would become

{'T', 'r', 'e', 'e'}
2 Likes
local splitString: table = string.split("Hello", "")

Will return a table with all the characters separated in table values.

1 Like

What is with the syntax after declaring the variable “splitString”? Can you elaborate?

It’s a Luau (Roblox syntax) type-hint for the variable definition.

So in roblox lua we would do

local splitString = string.split(string, "")
``` ??

No, you would write it exactly how I just wrote it.

But my paradigm isn’t luau, isn’t there a way I can do it in the non typed language?

It’s the same. But if you want to not use type hinting just remove the : table after the variable.

1 Like

I think the syntax you’re asking for is this, which works:
local splitString = str:split( "" )

This syntax is no longer working as I tried you can just do

local table = string.split(msg," ")

Don’t confuse “string”, the library with “str”, a string variable in my example.
So in your example, my example form of syntax would be:
msg:split( "" )
(Notice the colon, not period.)