mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-07-16 08:52:59 +00:00
Add splitString to textutils
This commit is contained in:
parent
6363164f2b
commit
0b8ede22a7
@ -940,6 +940,32 @@ function urlEncode(str)
|
|||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Splits a string in a table
|
||||||
|
--
|
||||||
|
-- @tparam string pString The string to split
|
||||||
|
-- @tparam string pPattern At which character/pattern to split the string
|
||||||
|
-- @treturn table A table containing the splitted strings.
|
||||||
|
-- @usage args = textutils.splitString("arg1 arg2", " ")
|
||||||
|
-- @since edit this if it goes live (I hope it does)
|
||||||
|
function splitString(pString, pPattern)
|
||||||
|
local Table = {}
|
||||||
|
local fpat = "(.-)" .. pPattern
|
||||||
|
local last_end = 1
|
||||||
|
local s, e, cap = pString:find(fpat, 1)
|
||||||
|
while s do
|
||||||
|
if s ~= 1 or cap ~= "" then
|
||||||
|
table.insert(Table, cap)
|
||||||
|
end
|
||||||
|
last_end = e + 1
|
||||||
|
s, e, cap = pString:find(fpat, last_end)
|
||||||
|
end
|
||||||
|
if last_end <= #pString then
|
||||||
|
cap = pString:sub(last_end)
|
||||||
|
table.insert(Table, cap)
|
||||||
|
end
|
||||||
|
return Table
|
||||||
|
end
|
||||||
|
|
||||||
local tEmpty = {}
|
local tEmpty = {}
|
||||||
|
|
||||||
--- Provides a list of possible completions for a partial Lua expression.
|
--- Provides a list of possible completions for a partial Lua expression.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user