string.format

From ComputerCraft
Jump to navigation Jump to search

string.format
Function
Syntax
string.format()
Returns string output
API string
Source Lua

Replaces placeholder strings in a string with the specified arguments.

ExampleExampleReplace placeholders in a string
Replace %s with what the user enters.
Code
local name = read()
print(string.format("Hello, %s!", name))
Output Prints "Hello," and whatever the user entered.
ExampleExampleReplace placeholders in a variable
Replace %s with what the user enters.
Code
local name = read()
local output = "Hello, %s!"
print(output:format(name))
Output Prints "Hello," and whatever the user entered.