Module:Ustring/doc

&#x3c;!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see Wikidata) --&#x3e; This module directly imports all functions from the library. Documentation for each function can be found there.

The module takes an indefinite number of arguments. Arguments given as s1, s2, etc, are read first, and are used as strings. All remaining numerical arguments are coerced to number type if possible, and remain strings if not. If you wish for a numerical (i.e. unnamed or "1", "2") to remain a string, you can simply escape it by inserting &#x3c;code&#x3e;\&#x3c;/code&#x3e; at the beginning of the string.

Note that MediaWiki will always trim whitespace from named arguments; to give arguments with surrounding whitespace you must use unnamed parameters starting with &#x3c;code&#x3e;\&#x3c;/code&#x3e;.

You can also wrap results in tags. All other unused arguments will be passed to

Usage
&#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/code&#x3e; is equivalent to

Example using mw.ustring.sub
&#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e;

produces:

Example using mw.ustring.gsub
&#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e;

produces:

Example using mw.ustring.char
&#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x26;amp;amp;#&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e;

produces:

&#x26;amp;#

Example using mw.ustring.match
&#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e;

produces:

Note: Only the first match is returned. Additional returns are omitted because mw.ustring.gsub's second return value is generally undesirable.

Example using tag arguments
&#x3c;pre&#x3e;&#x3c;/pre&#x3e; produces:

Note that:

produces: &#x3c;syntaxhighlight lang="lua"&#x3e;&#x3c;/syntaxhighlight&#x3e;

Errors
Errors from accessing should be maintained, e.g.:

&#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e;

should produce:

and

&#x3c;code&#x3e;&#x3c;nowiki&#x3e;&#x3c;/nowiki&#x3e;&#x3c;/code&#x3e;

should produce: