Difference between revisions of "Template:Split/doc"
Line 88: | Line 88: | ||
</nowiki></pre> | </nowiki></pre> | ||
+ | <includeonly>[[Category:Auxiliary templates]]</includeonly> | ||
</noinclude>[[Category:Template documentation]]</noinclude> | </noinclude>[[Category:Template documentation]]</noinclude> |
Latest revision as of 17:40, 19 September 2023
Introduction
This template will split strings by incoming parameters, and saved one by one using multiple variables, mostly used in templates.
Usage
{{Split |str = String to be split |ptn = Characters or regular expressions used for splitting, supports formatting inside nowiki tags |name = Variable prefixes for split sections, default is foo |reg = When "on", regular mode is enabled. }}
In which:
{{#var:(n)}}
Holds the string obtained by splitting.{{#var:.count}}
holds the total number of strings obtained by splitting.- str, ptn and name also correspond to the anonymous parameters 1, 2, and 3, respectively
Examples
Example 1
{{Split|Hello,world!|,}} Split 1: {{#var:foo1}} Split 2: {{#var:foo2}} Total number of strings obtained by splitting: {{#var:foo.count}}
Split 1: Hello
Split 2: world!
Total number of strings obtained by splitting: 2
Example 2
{{split|str=a123b456c|ptn%d+|reg=on}} Split 1: {{#var:foo1}} Split 2: {{#var:foo2}} Split 3: {{#var:foo3}} Total number of strings obtained by splitting: {{#var:foo.count}}
Split 1: p
Split 2: t
Split 3: n
Total number of strings obtained by splitting: 6
Example 3
{{split|Moegirl+Welcome+pedia! ++to|+|str}} {{#var:str2}}{{#var:str5}}{{#var:str1}}{{#var:str3}} Total number of strings obtained by splitting: {{#var:str.count}}
WelcometoMoegirlPedia!
Total number of strings obtained by splitting: 5
(Because of one of the consecutive plus signs, is given an empty string)
Example 4
Use this template to split a received string in an agreed format in a template, used as multiple parameters. Because it's a template, no examples can be made here.
{{#fornumargs: num |value |{{split|{{#var:value}}|,}} {{ruby|{{#var:foo1}}|{{#var:foo2}}}} }}