string.gsub

string.gsub
Function
Syntax
string.gsub(
  • sentence : string
  • string : string
  • count? : number
)
Colon notation: sentence:gsub(
  • string : string
  • count? : number
)

Returns string
API string
Source Lua (source)

Replaces a string in a sentence.

ExampleReplace all letter "l"
All letters "l" have been replaced by the letter "L".
Code
<nowiki>
string.gsub("hello world","l","L")
    </nowiki>
Output heLLo worLd
ExampleLimit the substitutions
It limits the substitutions to the first 2 letters found
Code
<nowiki>
string.gsub("hello world","l","L",2)
    </nowiki>
Output heLLo world
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.