සැකිල්ල:Str index any/doc
This is a documentation subpage for සැකිල්ල:Str index any. It may contain usage information, categories and other content that is not part of the original සැකිල්ල page. |
The Template:str_index_any extracts a specified nth character from a string, even allowing for accented letters to be included in the string.
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}} → 3
- 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
[සංස්කරණය]- Template:Str index, template to extract for only non-accented characters
- Template:Str sub
- Template:Str sub long
- m:Template:Chr - similar to this template, but capable of returning a space