string.Replace

From GMod Wiki

Jump to: navigation, search
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: NewerShared.png
Exclamation.png 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

DescriptionReplaces a word with another in a string.
Used onNewerShared.png
Code
 
 
local text = "Testing my thing"
 
local text2 = string.Replace(text,"thing","script")
 
Msg(text2)
 
 
OutputTesting my script


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox