Progetto H — API Reference API & Scripting Documentation
Function Shared Native

string.gsub

Returns a copy of s in which all (or the first <code>n</code>, if given) occurrences of the <code>pattern</code> have been replaced by a replacement string specified by <code>repl</code>.

Syntax

Lua
string.gsub(string, pattern, replacement, maxReplaces)

Parameters

Name Type Default Description
string string String which should be modified.
pattern string The pattern that defines what should be matched and eventually be replaced.
replacement string In case of a string the matched sequence will be replaced with it. In case of a table, the matched sequence will be used as key and the table will tested for the key, if a value exists it will be used as replacement. In case of a function all matches will be passed as parameters to the function, the return value(s) of the function will then be used as replacement.
maxReplaces number Maximum number of replacements to be made.

Returns

  • string
  • number