Garry's Mod Wiki

Garry's Mod Wiki

  string string.PatternSafe( string str )

Description

Escapes all special characters within a string, making the string safe for inclusion in a Lua pattern.

Arguments

1 string str
The string to be sanitized

Returns

1 string
The string that has been sanitized for inclusion in Lua patterns

Example

Replaces all occurrences of "100%" in a string with "0%" and prints it.

We call string.PatternSafe here as '%' is a special character when used in Lua patterns.

local result = string.gsub( "You scored 100%!", string.PatternSafe( "100%" ), string.PatternSafe( "0%" ) ) print( result )
Output: You scored 0%!

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...