Notice: Failed to invoke Pygments: [Called from MediaWiki\SyntaxHighlight\SyntaxHighlight::highlightInner in /home/pi/www/gtac/wiki/wiki/extensions/SyntaxHighlight_GeSHi/includes/SyntaxHighlight.php at line 334] in /home/pi/www/gtac/wiki/wiki/includes/debug/MWDebug.php on line 507
Third Party Code: split - GTA Connected

Third Party Code: split

Revision as of 19:53, 14 August 2018 by Vortrex (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Split text by spacing, or by a Lua pattern.
This is useful to split the command arguments string in the function parameter for callbacks bound with addCommandHandler.

Code

Lua:

-- https://stackoverflow.com/questions/1426954/split-string-in-lua
function split(inputstr, sep)
	if sep == nil then
		sep = "%s"
	end
	local t={} ; i=1
	for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
		t[i] = str
		i = i + 1
	end
	return t
end

JavaScript:
JavaScript has a built-in split() method for string types: [1]

Squirrel:
Squirrel has a built-in split() method for string types: [2]