Jump to content
Wikimedia Meta-Wiki

Template:Sub/doc

From Meta, a Wikimedia project coordination wiki
This is a documentation subpage for Template:Sub.
It contains usage information, categories, and other content that is not part of the original template page.

Extracts a substring of a string.

Usage

[edit ]

{{sub|text|number of characters removed from the start|maximum length}}

  • "{{sub|20090624130510|0|0}}" gives "".
  • "{{sub|20090624130510|0|3}}" gives "200".
  • "{{sub|20090624130510|8|0}}" gives "".
  • "{{sub|20090624130510|8|3}}" gives "130".
  • "{{sub|café noir|0|4}}" gives "café".
  • "{{sub|café noir|1|3}}" gives "afé".
  • "{{sub|café noir|3|2}}" gives "é ".
  • "{{sub|café noir|4|2}}" gives " n".
  • "{{sub|22:06, 12 July 2010 User|19|5}}" gives " User".
  • "{{sub|22:06, 2 July 2010 User|19|4}}" gives "User".
  • "{{sub|123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123|0|200}}" gives "123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123".
  • "{{sub|123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123|1|200}}" gives "23456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123".
  • "{{sub|1*3456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123|1|200}}" gives "
  • 3456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123".

Limitation

[edit ]

<nowiki>...</nowiki> and <nowiki /> tags and their content are internally replaced by a code, which may affect the result:

  • "{{sub|<nowiki/>*café noir|1|9}}" gives "'"`UNIQ--".
  • "{{sub|*café noir|1|9}}" gives "café noir".

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|*test|1|4}}" gives "test".


See also

[edit ]


AltStyle によって変換されたページ (->オリジナル) /