模組:String utilities/doc
这是Module:String utilities的文档页面
Provides some utility functions for manipulating strings.
Functions
编辑format
编辑string_utilities.format( str, tbl )
This function, 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
编辑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"
- produces:
string_utilities.format("The set {\\op}1, 2, 3{\\cl} contains {\\\\hello} elements.", {["\\hello"]="three"})<tt>
- 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.
- produces: