The Template:str_index_any extracts a specified nth character from a string, even allowing for accented letters to be included in the string.
-
- {{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.
[edit] Examples
- {{ Str index any/doc |0123456789ABCDEF|15}} →
The Template:str_index_any extracts a specified nth character from a string, even allowing for accented letters to be included in the string.
-
- {{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.
[edit] Examples
- {{ Str index any/doc |0123456789ABCDEF|15}} → Template loop detected: Template:Str index any/doc
- {{ Str index any/doc |ÁBĆĎÉf-ABCDEF|4}} → Template loop detected: Template:Str index any/doc
- {{ Str len |{{ Str index any/doc |a b|1}}}} → 81
- {{ Str len |{{ Str index any/doc |a b|2}}}} → 81
- {{ Str len |{{ Str index any/doc |a b|3}}}} → 81
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/doc |a b|2}}>}} → 83
- {{ Str len |X{{ Str index any/doc |a b|2}}X}} → 83
- {{ Str len |X{{ Str index |a b|2}}X}} → 7
- X{{ Str index any/doc |a b|2}}X → XTemplate loop detected: Template:Str index any/docX
The same string-length problem occurs when using template {{ Str index }}. There might be other quirks as well, but most cases work as expected.
[edit] See also
Trimming templates:
- {{Trunc}} – To trim down to a specified number of characters.
- {{Trim}} — To trim any leading or trailing whitespace.
- {{Str left}} – To trim down to a specified number of characters, or duplicate the string to a specified number.
Analyzing templates:
- {{Str endswith}} – To check if a string ends with a given string.
- {{Str find}} – Returns the numerical location of a given string in a string, up to 50 characters.
- {{Chr}} – Returns a given character from a string, including a space.
- {{Str len}} – Returns a string's length. Can count up to 500 characters.
String length comparison templates:
- {{Str ≤ len}} – To check if a string is "shorter or equally long" or "longer" than a given length.
Sandboxes and test cases:
Technical stuff:
Feature requests:
- bugzilla:6455 - Set $wgPFEnableStringFunctions = true on WMF wikis
- bugzilla:26092 - Enable or install string parsing wikimarkup functionality on WMF wikis
- {{ Str index any/doc |ÁBĆĎÉf-ABCDEF|4}} →
The Template:str_index_any extracts a specified nth character from a string, even allowing for accented letters to be included in the string.
-
- {{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.
[edit] Examples
- {{ Str index any/doc |0123456789ABCDEF|15}} → Template loop detected: Template:Str index any/doc
- {{ Str index any/doc |ÁBĆĎÉf-ABCDEF|4}} → Template loop detected: Template:Str index any/doc
- {{ Str len |{{ Str index any/doc |a b|1}}}} → 81
- {{ Str len |{{ Str index any/doc |a b|2}}}} → 81
- {{ Str len |{{ Str index any/doc |a b|3}}}} → 81
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/doc |a b|2}}>}} → 83
- {{ Str len |X{{ Str index any/doc |a b|2}}X}} → 83
- {{ Str len |X{{ Str index |a b|2}}X}} → 7
- X{{ Str index any/doc |a b|2}}X → XTemplate loop detected: Template:Str index any/docX
The same string-length problem occurs when using template {{ Str index }}. There might be other quirks as well, but most cases work as expected.
[edit] See also
Trimming templates:
- {{Trunc}} – To trim down to a specified number of characters.
- {{Trim}} — To trim any leading or trailing whitespace.
- {{Str left}} – To trim down to a specified number of characters, or duplicate the string to a specified number.
Analyzing templates:
- {{Str endswith}} – To check if a string ends with a given string.
- {{Str find}} – Returns the numerical location of a given string in a string, up to 50 characters.
- {{Chr}} – Returns a given character from a string, including a space.
- {{Str len}} – Returns a string's length. Can count up to 500 characters.
String length comparison templates:
- {{Str ≤ len}} – To check if a string is "shorter or equally long" or "longer" than a given length.
Sandboxes and test cases:
Technical stuff:
Feature requests:
- bugzilla:6455 - Set $wgPFEnableStringFunctions = true on WMF wikis
- bugzilla:26092 - Enable or install string parsing wikimarkup functionality on WMF wikis
- {{ Str len |{{ Str index any/doc |a b|1}}}} → 500
- {{ Str len |{{ Str index any/doc |a b|2}}}} → 500
- {{ Str len |{{ Str index any/doc |a b|3}}}} → 500
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/doc |a b|2}}>}} → 500
- {{ Str len |X{{ Str index any/doc |a b|2}}X}} → 500
- {{ Str len |X{{ Str index |a b|2}}X}} → 7
- X{{ Str index any/doc |a b|2}}X → X
The Template:str_index_any extracts a specified nth character from a string, even allowing for accented letters to be included in the string.
-
- {{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.
[edit] Examples
- {{ Str index any/doc |0123456789ABCDEF|15}} → Template loop detected: Template:Str index any/doc
- {{ Str index any/doc |ÁBĆĎÉf-ABCDEF|4}} → Template loop detected: Template:Str index any/doc
- {{ Str len |{{ Str index any/doc |a b|1}}}} → 81
- {{ Str len |{{ Str index any/doc |a b|2}}}} → 81
- {{ Str len |{{ Str index any/doc |a b|3}}}} → 81
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/doc |a b|2}}>}} → 83
- {{ Str len |X{{ Str index any/doc |a b|2}}X}} → 83
- {{ Str len |X{{ Str index |a b|2}}X}} → 7
- X{{ Str index any/doc |a b|2}}X → XTemplate loop detected: Template:Str index any/docX
The same string-length problem occurs when using template {{ Str index }}. There might be other quirks as well, but most cases work as expected.
[edit] See also
Trimming templates:
- {{Trunc}} – To trim down to a specified number of characters.
- {{Trim}} — To trim any leading or trailing whitespace.
- {{Str left}} – To trim down to a specified number of characters, or duplicate the string to a specified number.
Analyzing templates:
- {{Str endswith}} – To check if a string ends with a given string.
- {{Str find}} – Returns the numerical location of a given string in a string, up to 50 characters.
- {{Chr}} – Returns a given character from a string, including a space.
- {{Str len}} – Returns a string's length. Can count up to 500 characters.
String length comparison templates:
- {{Str ≤ len}} – To check if a string is "shorter or equally long" or "longer" than a given length.
Sandboxes and test cases:
Technical stuff:
Feature requests:
- bugzilla:6455 - Set $wgPFEnableStringFunctions = true on WMF wikis
- bugzilla:26092 - Enable or install string parsing wikimarkup functionality on WMF wikis
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.
[edit] See also
Trimming templates:
- {{Trunc}} – To trim down to a specified number of characters.
- {{Trim}} — To trim any leading or trailing whitespace.
- {{Str left}} – To trim down to a specified number of characters, or duplicate the string to a specified number.
Analyzing templates:
- {{Str endswith}} – To check if a string ends with a given string.
- {{Str find}} – Returns the numerical location of a given string in a string, up to 50 characters.
- {{Chr}} – Returns a given character from a string, including a space.
- {{Str len}} – Returns a string's length. Can count up to 500 characters.
String length comparison templates:
- {{Str ≤ len}} – To check if a string is "shorter or equally long" or "longer" than a given length.
Sandboxes and test cases:
Technical stuff:
Feature requests:
- bugzilla:6455 - Set $wgPFEnableStringFunctions = true on WMF wikis
- bugzilla:26092 - Enable or install string parsing wikimarkup functionality on WMF wikis