Difference between revisions of "Template:CleanUpString"

From Pathfinder Wiki
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly><onlyinclude>{{
+
<includeonly><onlyinclude>{{#vardefine: cleanedString|{{#replace:{{{string}}}|&#38;|&}} }}
#vardefine: cleanedString|{{#replace|{{{string}}}|&#38;|&}} }}{{
+
{{#vardefine: cleanedString|{{#replace:{{#var:cleanedString}}|&#39;|'}} }}
#vardefine: cleanedString|{{#replace|{{{cleanedString}}}|&#39;|'}} }}</onlyinclude></includeonly>
+
{{#vardefineecho: cleanedString|{{#replace:{{#var:cleanedString}}|&#039;|'}} }}</onlyinclude></includeonly>
 
This template removes the hexvalue of & and ' characters from strings and replaces them. It is introduced for links because some of them have those in them and won't work if they do.
 
This template removes the hexvalue of & and ' characters from strings and replaces them. It is introduced for links because some of them have those in them and won't work if they do.
 +
 +
==How it works==
 +
First it takes the input string <nowiki>{{{string}}}</nowiki> and replaces the &. This resuld is saved with <nowiki>#vardefine</nowiki> into the variable cleanedString.
 +
Then it takes the cleanedString, previously saved, and replaces the '. That one is saved into cleanedString again, overwritting it's previous content.
 +
But as that is the last charakter it is saved with <nowiki>#vardefineecho</nowiki> that is the "return value" of the template!

Latest revision as of 18:22, 19 March 2021

This template removes the hexvalue of & and ' characters from strings and replaces them. It is introduced for links because some of them have those in them and won't work if they do.

How it works

First it takes the input string {{{string}}} and replaces the &. This resuld is saved with #vardefine into the variable cleanedString. Then it takes the cleanedString, previously saved, and replaces the '. That one is saved into cleanedString again, overwritting it's previous content. But as that is the last charakter it is saved with #vardefineecho that is the "return value" of the template!