String
string.split
Shared
Splits a string into a table of substrings using a separator
Syntax
local parts = string.split(input, separator)Parameters
| Type | Name | Description |
|---|---|---|
string | input | String to be splitted |
string | separator | Delimiter string to split by |
Returns
| Type | Name | Description |
|---|---|---|
table | parts | Array of split substrings |
Examples
--Split by comma
local parts = string.split("apple,banana,orange", ",")
engine.print(parts[1]) --apple
engine.print(parts[2]) --banana
engine.print(parts[3]) --orange--Split by multiple characters
local parts = string.split("one::two::three", "::")
engine.print(parts[1]) --one
engine.print(parts[2]) --two
engine.print(parts[3]) --three--Split by space
local words = string.split("hello world lua", " ")
for i, word in ipairs(words) do
engine.print(word)
end
--Output: hello, world, lua