Split: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
[[Category:Incomplete]]
__NOTOC__
__NOTOC__
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.  
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.  
==Syntax==
<syntaxhighlight lang="lua">table split ( string stringToSplit, string separatingChar )</syntaxhighlight>
===Required Arguments===
* '''stringToSplit''' The string you wish to split into parts.
* '''separatingChar''' The character you want to use to split


==Returns==
==Returns==
Returns a table of the sub-strings.
Returns a table of the sub-strings.
==Syntax==
<syntaxhighlight lang="lua">table split ( string, separatingchar )</syntaxhighlight>


==Example==
==Example==
This examples takes any console text input and splits it into parts.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function onConsole ( player, text )
function onConsole ( player, text )

Revision as of 11:59, 12 July 2006

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.

Syntax

table split ( string stringToSplit, string separatingChar )

Required Arguments

  • stringToSplit The string you wish to split into parts.
  • separatingChar The character you want to use to split

Returns

Returns a table of the sub-strings.

Example

This examples takes any console text input and splits it into parts.

function onConsole ( player, text )
  splittext = split ( text, 32 ) -- Grab the table of tokens
    for splitKey, splitVal in splittext do -- for each token there..
      outputChatBox ( "key: " .. splitKey .. " val: " .. splitVal ) -- output the index and token
    end
end

See Also