Garry's Mod Wiki

string.Explode

table string.Explode( string separator, string str, boolean use_patterns )

Description

Splits a string up wherever it finds the given separator.

This is the reverse of string.Implode.

Arguments

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

Returns

1 table
Exploded string as a numerical sequential table.

Example

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 )
Output: 1 = hello 2 = there 3 = my 4 = name 5 = is 6 = Player1

Example

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)
Output: Player1 set their health to 100.

Page Links


Special Pages


Wikis

?

Render Time: 44ms

DB GetPage 5
Generate Html 13
SaveChanges 10
Render Body 0
Render Sidebar 12