Created page with "== Introduction == This template will split strings by incoming parameters, and saved one by one using multiple variables, mostly used in templates. == Usage == <pre><nowiki>..." |
No edit summary |
||
Line 15: | Line 15: | ||
* <code><nowiki>{{#var:(n)}}</nowiki></code> Holds the string obtained by splitting. | * <code><nowiki>{{#var:(n)}}</nowiki></code> Holds the string obtained by splitting. | ||
* <code><nowiki>{{#var:.count}}< | * <code><nowiki>{{#var:.count}}</nowiki></code> holds the total number of strings obtained by splitting. | ||
* str, ptn and name also correspond to the anonymous parameters 1, 2, and 3, respectively | * str, ptn and name also correspond to the anonymous parameters 1, 2, and 3, respectively | ||
== | == Examples == | ||
=== | === Example 1 === | ||
<pre><nowiki> | <pre><nowiki> | ||
{{Split|Hello,world!|,}} | {{Split|Hello,world!|,}} | ||
Line 38: | Line 38: | ||
Total number of strings obtained by splitting: {{#var:foo.count}} | Total number of strings obtained by splitting: {{#var:foo.count}} | ||
=== | === Example 2 === | ||
<pre><nowiki> | <pre><nowiki> | ||
{{split|str=a123b456c|ptn%d+|reg=on}} | {{split|str=a123b456c|ptn%d+|reg=on}} | ||
Line 61: | Line 61: | ||
Total number of strings obtained by splitting: {{#var:foo.count}} | Total number of strings obtained by splitting: {{#var:foo.count}} | ||
=== | === Example 3 === | ||
<pre><nowiki> | <pre><nowiki> | ||
{{split|Moegirl+Welcome+pedia! ++to|+|str}} | {{split|Moegirl+Welcome+pedia! ++to|+|str}} | ||
Line 70: | Line 70: | ||
</nowiki></pre> | </nowiki></pre> | ||
{{split| | {{split|Moegirl+Welcome+Pedia! ++to|+|str}} | ||
{{#var:str2}}{{#var:str5}}{{#var:str1}}{{#var:str3}} | {{#var:str2}}{{#var:str5}}{{#var:str1}}{{#var:str3}} | ||
Line 78: | Line 78: | ||
(Because of one of the consecutive plus signs, <code>{{#var:str4}}</code> is given an empty string) | (Because of one of the consecutive plus signs, <code>{{#var:str4}}</code> 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. | 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. | ||
This template will split strings by incoming parameters, and saved one by one using multiple variables, mostly used in templates.
{{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.{{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
{{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
{{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)
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}}}} }}