Template:Sub
Finds a substring of a string. Works for the first 100 characters of the given string only.
Contents |
Usage [edit]
{{sub|text|number of characters removed from the start|length}}
"{{sub|20090624130510|0|0}}"gives "" [1]"{{sub|20090624130510|0|3}}"gives "200" [2]"{{sub|20090624130510|8|0}}"gives "" [3]"{{sub|20090624130510|8|3}}"gives "130" [4]"{{sub|café noir|0|4}}"gives "café" [5]"{{sub|café noir|1|3}}"gives "afé" [6]"{{sub|café noir|3|2}}"gives "é " [7]"{{sub|café noir|4|2}}"gives " n" [8]"{{sub|22:06, 12 July 2010 User|19|5}}"gives " User" [9]"{{sub|22:06, 2 July 2010 User|19|4}}"gives "User" [10]"{{sub|1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123|1|200}}"gives "234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" [11]
"{{sub|123456789:01234567890123;4567890123456*7890123456#789012345{|6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123|0|200}}" gives "123456789:01234567890123;4567890123456*7890123456#789012345{|6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234" [12]
"{{sub|123456789:01234567890123;4567890123456*7890123456#789012345{|6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123|1|200}}" gives "23456789:01234567890123;4567890123456*7890123456#789012345{|678901234567890123456789012345678901234" [13]
"{{sub|123456789:01234567890123;4567890123456*7890123456#789012345{{{!}}6789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123|59|10}}" gives the wikitext "
{|67890123"
If the second parameter is zero a separate, simpler method is used for efficiency. This is also why some limitations do not apply in this case:
Only operates on a limited character set.
<nowiki> tags and their content are internally replaced by a code, which may affect the result.
Template argument size [edit]
A limitation is the maximum template argument size of 2,048,000 bytes per page.
For calls of this template this depends on length of the substring to be found. Also, the higher the values in the index range, the more it is. It depends also on the position of the characters of the substring in the list of supported characters in Template:Chr/list: the later it occurs in the list, the more it is. See also Template:Chr#Template argument size.
Examples with the last character in the list, ŋ (worst case):
{{sub|ŋaŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋ|1|1}} gives a template argument size of 4530 bytes.
{{sub|ŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋ|1|50}} gives a template argument size of 1,729,754 bytes.
For a substring starting at the start of the string the template applies a much more efficient method, with a much less template argument size:
{{sub|ŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋŋ|0|50}} gives a template argument size of 407 bytes.
Automatic newline [edit]
Due to the automatic newline feature/bug a newline is added before any "*", "#", ":", and ";" in the substring, except when the substring starts at the start of the string:
"{{sub|{{padleft:|100|{{Help:Template}}}}|0|100}}" gives "
"{{sub|{{padleft:|100|{{Help:Template}}}}|2|98}}"gives "| style="padding:5px; border:1px solid #ffcc00; text-align:center; background:#FFFDDF; width:100%;"