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...")
 
(support for broken ranges)
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}}.
 +
 +
Example: <nowiki>{{pagecount|12-14,17,20-21}}</nowiki> becomes {{pagecount|12-14,17,20-21}}.
  
 
[[Category:Sega Retro templates]]</noinclude>
 
[[Category:Sega Retro templates]]</noinclude>

Revision as of 20:40, 15 July 2016

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.