Modulo:string utilities/dokumentado

El Vikivortaro
Salti al navigilo Salti al serĉilo

Tio estas la paĝo de la dokumentado por Modulo:string utilities

Provides some utility functions for manipulating strings.

Functions[redakti]

format[redakti]

string_utilities.format( str, tbl )

This funtion, unlike string.format and mw.ustring.format, takes just two parameters—a format string and a table—and replaces all instances of {param_name} in the format string with the table's entry for param_name. The opening and closing brace characters can be escaped with {\op} and {\cl}, respectively. A table entry beginning with a slash can be escaped by doubling the initial slash.

Examples[redakti]
  • string_utilities.format("{foo} fish, {bar} fish, {baz} fish, {quux} fish", {["foo"]="one", ["bar"]="two", ["baz"]="red", ["quux"]="blue"})
    produces: "one fish, two fish, red fish, blue fish"
  • string_utilities.format("The set {\\op}1, 2, 3{\\cl} contains {\\\\hello} elements.", {["\\hello"]="three"})
    produces: "The set {1, 2, 3} contains three elements."
    • Note that the single and double backslashes should be entered as double and quadruple backslashes when quoted in a literal string.