Garry's Mod Wiki


  number, number, string string.find( string haystack, string needle, number startPos = 1, boolean noPatterns = false )


Attempts to find the specified substring in a string.

This function uses Lua Patterns by default.


1 string haystack
The string to search in.
2 string needle
The string to find, can contain patterns if enabled.
3 number startPos = 1
The position to start the search from, can be negative start position will be relative to the end position.
4 boolean noPatterns = false
Disable patterns.


1 number
Starting position of the found text, or nil if the text wasn't found
2 number
Ending position of found text, or nil if the text wasn't found
3 string
Matched text for each group if patterns are enabled and used, or nil if the text wasn't found


Change the word "heck" to "****" in chat messages

hook.Add( "PlayerSay", "NoHeckHere", function( ply, text ) local heckStart, heckEnd = string.find( text:lower(), "heck" ) if heckStart then local civilText = string.sub( text, 1, heckStart - 1 ) .. "****" .. string.sub( text, heckEnd + 1 ) return civilText end end )