Difference between revisions of "Pagecount"

From Sega Retro

(Created page with "<includeonly>{{#if: {{#pos:{{{1}}}|-}} | {{#expr: {{#explode:{{{1}}}|-|1}}-{{#explode:{{{1}}}|-|0}}+1 }} | 1 }}</includeonly><noinclude> Calculate the size of a range (inclusi...")
 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
<includeonly>{{#if: {{#pos:{{{1}}}|-}} | {{#expr: {{#explode:{{{1}}}|-|1}}-{{#explode:{{{1}}}|-|0}}+1 }} | 1 }}</includeonly><noinclude>
+
<includeonly>{{#vardefine:pagecountresult|0}}
Calculate the size of a range (inclusive) given by the format "a-b".
+
{{#loop: chunknum
 +
|0
 +
|{{#expr:{{charcount|{{{1}}}|,}}+1}}
 +
|{{#vardefine:chunk|{{#explode:{{{1}}}|,|{{#var:chunknum}}}}}}
 +
{{addvar|pagecountresult|{{#if: {{#pos:{{#var:chunk}}|-}} | {{#expr: {{#explode:{{#var:chunk}}|-|1}}-{{#explode:{{#var:chunk}}|-|0}}+1 }} | 1 }}}}
 +
}}{{#var:pagecountresult}}</includeonly><noinclude>
 +
Calculate the size of a range (inclusive) given by the format "a-b". It also works with broken ranges in the format "a-b,c-d".
  
 
Example: <nowiki>{{pagecount|12-14}}</nowiki> becomes {{pagecount|12-14}}.
 
Example: <nowiki>{{pagecount|12-14}}</nowiki> becomes {{pagecount|12-14}}.
  
[[Category:Sega Retro templates]]</noinclude>
+
Example: <nowiki>{{pagecount|12-14,17,20-21}}</nowiki> becomes {{pagecount|12-14,17,20-21}}.
 +
 
 +
[[Category:Templates]]</noinclude>

Latest revision as of 14:06, 1 January 2022

Calculate the size of a range (inclusive) given by the format "a-b". It also works with broken ranges in the format "a-b,c-d".

Example: {{pagecount|12-14}} becomes 3.

Example: {{pagecount|12-14,17,20-21}} becomes 6.