Garry's Mod Wiki

Garry's Mod Wiki

  table string.Explode( string separator, string str, boolean withpattern = false )


Splits a string up wherever it finds the given separator.

The function string.Split is an alias of this function, except that function doesn't support using patterns.

See string.Implode for the reverse operation of this function.


1 string separator
The string will be separated wherever this sequence is found.
2 string str
The string to split up.
3 boolean withpattern = false
Set this to true if your separator is a pattern.


1 table
Exploded string as a numerical sequential table.


Splits a sentence into a table of the words in it.

local sentence = "hello there my name is Player1" local words = string.Explode( " ", sentence ) PrintTable( words )
1 = hello 2 = there 3 = my 4 = name 5 = is 6 = Player1


Uses Explode to sort through words that a player says.

hook.Add( "PlayerSay", "GiveHealth", function( ply, text ) local playerInput = string.Explode( " ", text ) if ( playerInput[1] == "!givehealth" ) then if ( tonumber( playerInput[2] ) ) then ply:SetHealth( tonumber( playerInput[2] ) ) print( ply:Nick() .. " set their health to " .. playerInput[2] ) end end end)
Player1 set their health to 100.


Splits a sentence into a table at every digit.

local sentence = "Seperated 4 every digit like 1 and 2" local words = string.Explode("%d", sentence, true) PrintTable( words )
1 = Seperated 2 = every digit like 3 = and 4 =

This site is a community mirror of the official Garry's Mod wiki.. This site is not maintained by Facepunch Studios.

Page content is automatically updated twice a day. Edits and history are not available.

Last Parsed: Loading...