Content deleted Content added
high-use |
+Cat |
||
(10 intermediate revisions by 7 users not shown) | |||
Line 15:
=== title ===
The title function capitalises the first letter of each word in the text, apart from a number of short words
This is a very simplistic algorithm; see [[:Template:Title case/doc]] for some of its limitations.
=== sentence ===
Line 54 ⟶ 56:
=== split ===
The ''split'' function splits text at boundaries specified by separator and returns the chunk for the index idx (starting at 1). It can use positional parameters or named parameters (but these should not be mixed):
* <code><nowiki>{{#invoke:String2 |split |text |separator |index |true/false}}</nowiki></code>▼
; Usage
* <code><nowiki>{{#invoke:String2 |split |txt=text |sep=separator |idx=index |plain=true/false}}</nowiki></code>▼
▲
Any double quotes (") in the separator parameter are stripped out, which allows spaces and wikitext like <code><nowiki>["[</nowiki></code> to be passed. Use <code>{{tl|!}}</code> for the pipe character <code>|</code>.
Line 62 ⟶ 67:
The index parameter is optional; it defaults to the first chunk of text.
The
=== stripZeros ===
Line 82 ⟶ 87:
* First positional parameter or |text is the text to be searched for.
* Optional parameter |title is the page title, defaults to the current page.
* Optional parameter |plain is either true for a plain search (default), or false for a [[mw:Extension:Scribunto/Lua reference manual #Patterns|Lua pattern]] search.
* Optional parameter |nomatch is the value returned when no match is found; default is nothing.
Line 100 ⟶ 105:
The strip function strips the first positional parameter of the characters or pattern supplied in the second positional parameter.
; Usage
: <code><nowiki>{{#invoke:String2|strip|</nowiki><var>source_string</var>|<var>characters_to_strip</var>|<var>plain_flag</var>}}</code>
: <code><nowiki>{{#invoke:String2|strip|</nowiki>source=|chars=|plain=}}</code>
; Examples
: <code><nowiki>{{#invoke:String2|strip|abc123def|123}}</nowiki></code> → {{#invoke:String2|strip|abc123def|123}}
: <code><nowiki>{{#invoke:String2|strip|abc123def|%d+|false}}</nowiki></code> → {{#invoke:String2|strip|abc123def|%d+|false}}
: <code><nowiki>{{#invoke:String2|strip|source=abc123def|chars=123}}</nowiki></code> → {{#invoke:String2|strip|source=abc123def|chars=123}}
: <code><nowiki>{{#invoke:String2|strip|source=abc123def|chars=%d+|plain=false}}</nowiki></code> → {{#invoke:String2|strip|source=abc123def|chars=%d+|plain=false}}
=== matchAny ===
Line 133 ⟶ 148:
A startswith function similar to {{ml|string|endswith}}. Both parameters are required, although they can be blank. Leading and trailing whitespace ''is'' counted, use named parameters to avoid this if required. Outputs "yes" for true and blank for false so may be passed directly to #if.
{{markup|padding=1px 5px|
<nowiki>{{#invoke:string2|startswith|search|se}}</nowiki>|{{#invoke:string2|startswith|search|se}}|
<nowiki>{{#invoke:string2|startswith|search|ch}}</nowiki>|{{#invoke:string2|startswith|search|ch}}}}<!-- Template:Mra -->
===isnumeric===
Implements {{tl|isnumeric}}, which tests whether a value is numeric (or at least, that it can be treated as such by the [[:mw:Extension:Scribunto/Lua_reference_manual#Language_library|Scribunto language library]]). By default, it will pass through the parameter if it's numeric and be blank if it's not. If the parameter <code>boolean=true</code> is given, then it will output <code>1</code> if numeric and <code>0</code> if not numeric.
{{markup|padding=1px 5px|
<nowiki>{{#invoke:string2|isnumeric|1,327.50}}</nowiki>|{{#invoke:string2|isnumeric|1,327.50}}|
<nowiki>{{#invoke:string2|isnumeric|9,999 (1950)}}</nowiki>|{{#invoke:string2|isnumeric|9,999 (1950)}}|
<nowiki>{{#invoke:string2|isnumeric|1,327.50|boolean=true}}</nowiki>|{{#invoke:string2|isnumeric|1,327.50|boolean=true}}|
<nowiki>{{#invoke:string2|isnumeric|9,999 (1950)|boolean=true}}</nowiki>|{{#invoke:string2|isnumeric|9,999 (1950)|boolean=true}}}}
== Usage ==
Line 180 ⟶ 204:
| <nowiki>{{#invoke:String2| ucfirst | human X chromosome }}</nowiki>
| {{#invoke:String2| ucfirst | human X chromosome}}
|-▼
| <nowiki>{{#invoke:String2 |
| {{#invoke:String2 |
|-▼
| <nowiki>{{#invoke:String2 |
| {{#invoke:String2 |
|-
|
Line 201 ⟶ 231:
| <nowiki>{{#invoke:String2| sentence | [[trimix (breathing gas)|trimix]] }}</nowiki>
| {{#invoke:String2| sentence | [[trimix (breathing gas)|trimix]] }}
▲|-
▲| <nowiki>{{#invoke:String2 | sentence | {{#invoke:WikidataIB |getValue</nowiki><br /><nowiki>| P136 |fetchwikidata=ALL |onlysourced=no |qid=Q1396889}} }}</nowiki>
▲| {{#invoke:String2 | sentence | {{#invoke:WikidataIB |getValue |P136 |fetchwikidata=ALL |onlysourced=no |qid=Q1396889}} }}
▲|-
▲| <nowiki>{{#invoke:String2 | sentence | {{#invoke:WikidataIB |getValue</nowiki><br /><nowiki>| P106 |fetchwikidata=ALL |list=hlist |qid=Q453196}} }}</nowiki>
▲| {{#invoke:String2 | sentence | {{#invoke:WikidataIB |getValue |P106 |fetchwikidata=ALL |list=hlist |qid=Q453196}} }}
|-
| <nowiki>{{#invoke:String2| sentence | }}</nowiki>
Line 275 ⟶ 299:
{{Case templates see also}}
Templates that implement
* {{tl|nowiki}}
* {{tl|nowiki2}}
<includeonly>{{Sandbox other||
[[Category:Modules that manipulate strings|*]]
[[Category:Template metamodules]]
}}</includeonly>
|