Split: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 18: | Line 18: | ||
This examples takes any console text input and splits it into parts. | This examples takes any console text input and splits it into parts. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function onConsole ( | function onConsole ( text ) | ||
-- Grab the table of tokens | -- Grab the table of tokens | ||
splittext = split ( text, 32 ) | splittext = split ( text, 32 ) | ||
-- for each token there.. | -- for each token there... | ||
for splitKey, splitVal in ipairs(splittext) do | for splitKey, splitVal in ipairs(splittext) do | ||
-- output the index and token | -- output the index and token | ||
outputChatBox ( | outputChatBox ( splitKey .. ": " .. splitVal ) | ||
end | end | ||
end | end | ||
addEventHandler ( "onConsole", getRootElement ( ), onConsole ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Utility functions}} | {{Utility functions}} |
Revision as of 18:50, 15 August 2007
This function splits a string into sub-strings. You specify a character that will act as a separating character; this will determine where to split the sub-strings. For example, it can split the string "Hello World" into two strings containing the two words, by spliting using a space as a seperating character.
Note: You can use the function gettok to retrieve a single token from the string at a specific index. This may be faster for one-off lookups, but considerably slower if you are going to check each token in a long string.
Syntax
table split ( string stringToSplit, int separatingChar )
Required Arguments
- stringToSplit The string you wish to split into parts.
- separatingChar The character you want to use to split (ASCII number)
Returns
Returns a table of the sub-strings.
Example
This examples takes any console text input and splits it into parts.
function onConsole ( text ) -- Grab the table of tokens splittext = split ( text, 32 ) -- for each token there... for splitKey, splitVal in ipairs(splittext) do -- output the index and token outputChatBox ( splitKey .. ": " .. splitVal ) end end addEventHandler ( "onConsole", getRootElement ( ), onConsole )
See Also
- addDebugHook
- base64Decode
- base64Encode
- debugSleep
- decodeString
- encodeString
- fromJSON
- generateKeyPair
- getColorFromString
- getDevelopmentMode
- getDistanceBetweenPoints2D
- getDistanceBetweenPoints3D
- getEasingValue
- getNetworkStats
- getNetworkUsageData
- getPerformanceStats
- getRealTime
- getTickCount
- getTimerDetails
- getTimers
- getFPSLimit
- getUserdataType
- getVersion
- gettok
- isTransferBoxVisible
- setTransferBoxVisible
- hash
- inspect
- interpolateBetween
- iprint
- isOOPEnabled
- isTimer
- killTimer
- md5
- passwordHash
- passwordVerify
- pregFind
- pregMatch
- pregReplace
- removeDebugHook
- resetTimer
- setDevelopmentMode
- setFPSLimit
- setTimer
- ref
- deref
- sha256
- split
- teaDecode
- teaEncode
- toJSON
- tocolor
- getProcessMemoryStats
- utfChar
- utfCode
- utfLen
- utfSeek
- utfSub
- bitAnd
- bitNot
- bitOr
- bitXor
- bitTest
- bitLRotate
- bitRRotate
- bitLShift
- bitRShift
- bitArShift
- bitExtract
- bitReplace