Template:Str index
Jump to navigation
Jump to search
This template returns a single character from the target string at the given position.
Usage
{{str index|target_string|position_index}}
Parameters
- target_string
- The string to search
- position_index
- The index for the character to return
The first character has an index value of 1.
If one requests a negative value, this function will select a character by counting backwards from the end of the string. In other words pos = -1 is the same as asking for the last character.
A requested value of zero, or a value greater than the length of the string returns an error.
Examples
{{str index|Great sentence!|4}}
yields: a{{str index|Great sentence!|-2}}
yields: e
This template was adapted from Template:Str index on Wikipedia.
Adaptation is noted for reference and attribution only. This template may differ from the original in function or in usage.
Adaptation is noted for reference and attribution only. This template may differ from the original in function or in usage.
The above documentation is transcluded from Template:Str index/doc.
Editors can experiment in this template's sandbox and testcases pages.
Please add categories to the /doc subpage. Subpages of this template.
Editors can experiment in this template's sandbox and testcases pages.
Please add categories to the /doc subpage. Subpages of this template.