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
local parts = string.split("apple,banana,orange", ",")
engine.print("info", parts[1]) --'apple'
engine.print("info", parts[2]) --'banana'
engine.print("info", parts[3]) --'orange'local parts = string.split("one::two::three", "::")
engine.print("info", parts[1]) --'one'
engine.print("info", parts[2]) --'two'
engine.print("info", parts[3]) --'three'local words = string.split("hello world lua", " ")
for i, word in ipairs(words) do
engine.print("info", word)
end
--[[
Output:
'hello'
'world'
'lua'
]]