string.Replace
From GMod Wiki
Function | |
Syntax |
string.Replace( String text, String to_be_replaced, String replace_with ) Where is this used? |
Description: | |
Replaces any instances of "to_be_replace" in the string "text" with "replace_with" | |
Returns: | String |
Part of Library: | String |
Realm: | |
Warning: | This is a slow function. Overuse of it will cause lag! (there's a better alternative: string.gsub) |
BBCode Link: | [b][url=http://wiki.garrysmod.com/?title=String.Replace]String.Replace [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] |
Example
Description | Replaces a word with another in a string. |
---|---|
Used on | |
Code | local text = "Testing my thing" local text2 = string.Replace(text,"thing","script") Msg(text2) |
Output | Testing my script |
Additional Notes
- Using string.gsub is most of the time a better idea than using this function. It's faster because it's already build in Lua, and this function is added later by Garry.