Template:Str index any: Difference between revisions
(port from wikipedia:template:str index any) |
m (Protected "Template:Str index any": If you'd like to suggest changes to this template, please do so at forum:Panopticon. This template is being protected because it impacts many other pages and templates. ([edit=sysop] (indefinite) [move=sysop] (i) |
Latest revision as of 05:17, 15 May 2012
Usage
- {{str index any|text|n}} = Returns the n-th character of text.
Supports a larger character set, allowing the text to have accented letters. Returns an error message for unknown characters. Returns   for a blank space.
Examples
- {{ Str index any |0123456789ABCDEF|15}} → E
- {{ Str index any |ÁBĆĎÉf-ABCDEF|4}} → Ď
- {{ Str len |{{ Str index any |a b|1}}}} → 1
- {{ Str len |{{ Str index any |a b|2}}}} → 5
- {{ Str len |{{ Str index any |a b|3}}}} → 1
The last example shows extraction of letter "b" with string length as 1. The prior example extracts a blank but considers the length as 5 for the 5 characters " " even though there is only 1 space, and hence, {{str len| }} → 5. If surrounded by 2 other characters, then the length might be totalled incorrectly as 7 (rather than 3 characters):
- {{ Str len |<{{ Str index any |a b|2}}>}} → 7
- {{ Str len |X{{ Str index any |a b|2}}X}} → 7
- {{ Str len |X{{ Str index |a b|2}}X}} → 31
- X{{ Str index any |a b|2}}X → X X
The same string-length problem occurs when using template {{ Str index }}. There might be other quirks as well, but most cases work as expected.