Template:Split/doc

From Moegirlpedia
< Template:Split
Revision as of 17:11, 19 September 2023 by LiaMinina (talk | contribs) (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>...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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}}<?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 == Syntax == === Syntax 1 === <pre><nowiki> {{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

Usage 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

Syntax 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}}


WelcometoMGPPedia!

Total number of strings obtained by splitting: 5

(Because of one of the consecutive plus signs, is given an empty string)

Syntax 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}}}}
}}