Jump to content

Module:Ustring/doc

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Codehydro (talk | contribs) at 16:42, 11 May 2017 (Created page with '{{Module rating |<!-- Values: pre-alpha • alpha • beta • release • protected -- If a rating not needed/relevant, delete this template call -->}} <!--...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

This module directly imports all functions from the mw.ustring library.

The module takes an indefinite number of arguments. All arguments are coerced as number type if possible. If you wish for something to remain a string, you can escape it with \, which in turn can be escaped by itself.

You can also wrap results in tags. All non-number indexed arguments will be passed to { frame:extensionTag

Usage

{{#invoke:Ustring|function_name|arg1|arg2|...}} is equivalent to mw.ustring.function_name( arg1, arg2, ... )

===Example using mw.ustring.sub:=== {{#invoke:Ustring|sub|abcde|2|4}} produces bcd

===Example using mw.ustring.gsub:=== {{#invoke:Ustring|match|abcde|(c%w)}} produces cd


Example using tag arguments

{{#invoke:Ustring|sub|{{Module:Ustring}}|274|548|tag=pre|style=background-color:#edd}}

produces:

tr_i = 1
			while fargs['s' .. str_i] do
				fargsused['s' .. str_i] = true
				args[str_i] = fargs['s' .. str_i]
				str_i = str_i + 1
			end
			for i, v in ipairs(fargs) do
				fargsused[i] = true
				args[i + str_i - 1] = tonumber(v) or v:gsub("^\\", "", 1)
			end
			if n