Split: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 9: Line 9:


==Example==
==Example==
<syntaxhighlight lang="lua">function onPlayerChat ( player, chat )
<syntaxhighlight lang="lua">
if (split (chat, 1, " ")) == "!createhydra")
function onConsole ( player, text )
  x, y, z = getPlayerPosition ( player )
  splittext = split ( text, 32 ) -- Grab the table of tokens
  createVehicle ( 520, x + 5, y, z )
    for splitKey, splitVal in splittext do -- for each token there..
  outputChatBox ( "You got a hydra", player )
      outputChatBox ( "key: " .. splitKey .. " val: " .. splitVal ) -- output the index and token
end
    end
end</syntaxhighlight>
  end
end
</syntaxhighlight>


==See Also==
==See Also==
{{Utility functions}}
{{Utility functions}}

Revision as of 20:54, 13 June 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.

Returns

Returns a table of the sub-strings.

Syntax

table split ( string, separatingchar )

Example

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
end

See Also