You are not currently logged in. Are you accessing the unsecure (http) portal? Click here to switch to the secure portal. |
Template:Str index any/doc
This is a documentation subpage for Template:Str index any. It contains usage information, categories, interlanguage links and other content that is not part of the original template page. |
The Template:str_index_any extracts a specified nth character from a string, even allowing for accented letters or diacritics to be included in the string. The string can be any length, but position n (parameter 2) is limited to 500 at most.
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 or other diacritical marks. Returns an error message for unknown characters. Returns   for a blank space, which can be converted to a simple space by xspace.
Examples
- {{ Str index any |0123456789ABCDEF|15}} → E
- {{ Str index any |ÁBĆĎÉf-ABCDEF|4}} → Ď
- {{ Str index any |Very very...long string of 500 characteRs|499}} → R
- {{ 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}} → 7
- 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.
See also
Easy to use and efficient string length comparison templates:
- {{str ≥ len}} – To check if a string is "longer or equally long" vs. "shorter" than a given length.
- {{str ≤ len}} – To check if a string is "shorter or equally long" vs. "longer" than a given length.
- {{str ≠ len}} – To check if a string is "not equal" vs. "equal" to a given length.
- {{str ≤ ≥ len}} – To check all three of "shorter", "equal" and "longer" at the same time.
Much less efficient string length template:
- {{str len}} – Takes a string as parameter and returns its length. Can count up to 500 in length.
Technical stuff:
- mw:Help:Magic words – About
{{padleft:|}}
. - mw:Help:Extension:ParserFunctions – About
{{#ifeq:|||}}
etc.