From 'City of Adelaide' History and Genealogy Site
Jump to navigation
Jump to search
z
Template documentation
The Template:Str_index_code extracts a character from parameter 1, at the location in parameter 2, using an encode/decode method for handling special markup characters. Any character can be extracted, including: colon, semicolon, asterisk ('*') and hashmark ('#').
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 code |0123456789ABCDEF|15}} → E
- {{ Str index code |ÁBĆĎÉf-ABCDEF|4}} → Ď
- {{ Str index code |Very very...long string of 500 characteRs|499}} → R
- {{ Str len |{{ Str index code |a b|1}}}} → 1
- {{ Str len |{{ Str index code |a b|2}}}} → 34
- {{ Str len |{{ Str index code |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 code |a b|2}}>}} → 36
- {{ Str len |X{{ Str index code |a b|2}}X}} → 36
- {{ Str len |X{{ Str index |a b|2}}X}} → 3
- X{{ Str index code |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
String handling templates |
|---|
| As of February 2013, these templates are being optimised using Lua modules. | | | Trim by counting |
- {{Str mid}} – To return a substring, specified by its position and length.
- {{Trunc}} – To trim down to a specified number of characters.
- {{Str left}} – To trim down to a specified number of characters, or duplicate the string to a specified number.
- {{Str crop}} – To crop a specified number of characters off the end.
- {{Chop head and tail}} – To crop a specified number of characters off the beginning and end.
- {{Str right}} – To trim the first specified number of characters.
- {{Str rightc}} – To return a number of characters from the end, returns a parameter if the string is empty.
- {{Str rightmost}} – To trim down to the last specified number of characters.
- {{Str sub old}} – To trim down to a specified number, starting at a given number from the left.
- {{Str sub new}} – Select a substr based on starting and ending index.
- {{Str index}} – Returns a given character from a string, but not accented letters.
|
|---|
| | Trim by checking | |
|---|
| | Insert strings |
- {{Loop}} – Repeat character string n times
- {{Replace}} – Returns the string, after replacing all occurrences of a specified string with another string.
- {{Strloc insert}} – Inserts a string at character location strloc, or appends if strloc<=0.
- {{Strloc prefix}} – Extracts string prefix up to location strloc, or whole string if strloc<=0.
- {{Str rep}} – Returns the string, after replacing the first occurrence of a specified string with another string.
|
|---|
| | Length |
- {{Str len}} – Returns a string's length.
- {{iflenge}} – IF LENgth Greater than or Equal to.
- {{Str ≥ len}} – To check if a string is "longer or equally long" or "shorter" than a given length.
- {{Str ≤ len}} – To check if a string is "shorter or equally long" or "longer" than a given length.
- {{Str ≠ len}} – To check if a string is "not equal" or "equal" to a given length.
- {{Str ≤ ≥ len}} – To check if a string is "shorter", "equal", or "longer" than a given length.
|
|---|
| | Analyse string |
- {{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.
- {{Strfind short}} – Returns the numerical location of a given string in a string.
- {{Str find0}} – Zero-based substring search.
- {{Str sub find}} – Searches a substring in a string at the given offset.
- {{ASCII code}} – Returns the ASCII value of a single character.
- {{Str letter}} – Returns the number of letters that begin a string.
- {{Str number}} – Returns the number of numbers that begin a string.
- {{Str gtr str}} – Compares two strings for alphabetical order, and returns a value accordingly.
- {{a or an}} – Takes a noun and produces the appropriate indefinite article, based on whether the first letter is a vowel.
|
|---|
| | Trim, dedicated |
- {{WikiProjectbasename}} - Removes "WikiProject" from a pagename
- {{Remove unranked}} - Removes the string "unranked_" from the left of a string (taxonomy).
- {{Ship prefix}} – Returns the length of a ship name prefix, if listed (ship names).
- {{Title without disambig}} – To trim off any parenthesis text at the end of a string (disambiguation).
- {{Title disambig text}} – Returns text in parenthesis at the end of a string (disambiguation).
- {{Unlink}} – Removes wikilink brackets (wikicode).
- {{Remove file prefix}}—Removes "File:" or "Image:" from filenames.
|
|---|
| | Technical developments | |
|---|
| |
|
bn:টেমপ্লেট:Str index any
de:Vorlage:Str index
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