Difference between revisions 3951195 and 6186690 on simplewiki{{Documentation subpage}} <!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS 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 === :: <nowiki>{{</nowiki>'''str index any'''|''text''|''n''<nowiki>}}</nowiki> = Returns the ''n''-th character of ''text''. Supports a larger character set, allowing the text to have accented letters or other [[diacritic]]al marks. Returns an error message for unknown characters. Returns &#32; for a blank space, which can be converted to a simple space by [[Template:Xspace|xspace]]. === Examples === * {{tlp| {{BASEPAGENAME}} |0123456789ABCDEF|15}} → {{ {{BASEPAGENAME}} |0123456789ABCDEF|15}} * {{tlp| {{BASEPAGENAME}} |ÁBĆĎÉf-ABCDEF|4}} → {{ {{BASEPAGENAME}} |ÁBĆĎÉf-ABCDEF|4}} * <nowiki>{{</nowiki> {{BASEPAGENAME}} |Very very...long string of 500 characteRs|499<nowiki>}}</nowiki> → R * <nowiki>{{</nowiki> Str len |{{ {{BASEPAGENAME}} |a b|1<nowiki>}}}}</nowiki> → {{ Str len |{{ {{BASEPAGENAME}} |a b|1}}}} * <nowiki>{{</nowiki> Str len |{{ {{BASEPAGENAME}} |a b|2<nowiki>}}}}</nowiki> → {{ Str len |{{ {{BASEPAGENAME}} |a b|2}}}} * <nowiki>{{</nowiki> Str len |{{ {{BASEPAGENAME}} |a b|3<nowiki>}}}}</nowiki> → {{ Str len |{{ {{BASEPAGENAME}} |a b|3}}}} 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 "&#32;" even though there is only 1 space, and hence, <nowiki>{{str len|&#32;}}</nowiki> → {{str len| }}. If surrounded by 2 other characters, then the length might be totalled incorrectly as 7 (rather than 3 characters): * <nowiki>{{</nowiki> Str len |<{{ {{BASEPAGENAME}} |a b|2<nowiki>}}>}}</nowiki> → {{ Str len |<{{ {{BASEPAGENAME}} |a b|2}}>}} * <nowiki>{{</nowiki> Str len |X{{ {{BASEPAGENAME}} |a b|2<nowiki>}}X}}</nowiki> → {{ Str len |X{{ {{BASEPAGENAME}} |a b|2}}X}} * <nowiki>{{</nowiki> Str len |X{{ Str index |a b|2<nowiki>}}X}}</nowiki> → {{ Str len |X{{ Str index |a b|2}}X}} * <nowiki>X{{</nowiki> {{BASEPAGENAME}} |a b|2<nowiki>}}X</nowiki> → X{{ {{BASEPAGENAME}} |a b|2}}X The same string-length problem occurs when using template {{tl| Str index }}. There might be other quirks as well, but most cases work as expected. <includeonly> <!-- CATEGORIES AND INTERWIKIS HERE, THANKS --> [[Category:String manipulation templates]]⏎ ⏎ [[bn:টেমপ্লেট:Str index any]] [[de:Vorlage:Str index]] [[en:Template:Str index any]] [[es:Plantilla:Str index]] [[ja:Template:Str index any]] [[ka:თარგი:Str index any]] [[pt:Predefinição:Str index]] [[ru:Шаблон:Str index]] [[sl:Predloga:Str index any]] [[ur:Template:Str index any]] </includeonly> All content in the above text box is licensed under the Creative Commons Attribution-ShareAlike license Version 4 and was originally sourced from https://simple.wikipedia.org/w/index.php?diff=prev&oldid=6186690.
![]() ![]() This site is not affiliated with or endorsed in any way by the Wikimedia Foundation or any of its affiliates. In fact, we fucking despise them.
|