Template:Str left/doc: Difference between revisions
Template page
More actions
indented Usage line; noted 999 gets entire string; stops at limit of 500 but no message will be shown; put See-also text describing each link |
Restore appearance like documentation pages of similar templates. Remove superfluous, technical, or repeated parts. |
||
| Line 1: | Line 1: | ||
{{Documentation subpage}} | {{Documentation subpage}} | ||
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE --> | <!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE --> | ||
=== Usage === | === Usage === | ||
: <code>{{Tlx|Str left|<string>|<count>}}</code> | |||
Gives the <count> substring of characters from the start of the string (the substring has length <count>) | Gives the <count> substring of characters from the start of the string (the substring has length <count>). | ||
If <count> is invalid or empty, an empty string is returned. If undefined, it defaults to 1. | If <count> is invalid or empty, an empty string is returned. If undefined, it defaults to 1. | ||
=== Limitations === | === Limitations === | ||
* Length to 500: The maximum substring stops at 500 long, yet gives no error message. Only 500 characters can be extracted even if the <string> is | * Length to 500: The maximum substring stops at 500 long, yet gives no error message. Only 500 characters can be extracted even if the <string> is longer. | ||
* | * Inexpensive (uses no other templates). | ||
=== Examples === | === Examples === | ||
| Line 18: | Line 18: | ||
*<tt><nowiki>{{Str left| lorem ipsum dolor sit amet | 10 }}</nowiki></tt> → {{Str left| lorem ipsum dolor sit amet | 10 }} | *<tt><nowiki>{{Str left| lorem ipsum dolor sit amet | 10 }}</nowiki></tt> → {{Str left| lorem ipsum dolor sit amet | 10 }} | ||
*<tt><nowiki>{{Str left| lorem ipsum dolor sit amet | 1 }}</nowiki></tt> → {{Str left| lorem ipsum dolor sit amet | 1 }} | *<tt><nowiki>{{Str left| lorem ipsum dolor sit amet | 1 }}</nowiki></tt> → {{Str left| lorem ipsum dolor sit amet | 1 }} | ||
*<tt><nowiki>{{Str left| lorem ipsum dolor sit amet | }}</nowiki></tt> → {{Str left| lorem ipsum dolor sit amet | }} | *<tt><nowiki>{{Str left| lorem ipsum dolor sit amet | }}</nowiki></tt> → {{Str left| lorem ipsum dolor sit amet | }} | ||
*<tt><nowiki>{{Str left| lorem ipsum dolor sit amet }}</nowiki></tt> → {{Str left| lorem ipsum dolor sit amet }} | *<tt><nowiki>{{Str left| lorem ipsum dolor sit amet }}</nowiki></tt> → {{Str left| lorem ipsum dolor sit amet }} | ||
=== See also === | === See also === | ||
* {{ | * {{Tl|Trunc|<string>|<count>}} - truncate right-side of string | ||
* {{ | * {{Tl|Str right|<string>|<count>}} - extract remainder of string | ||
* {{ | * {{Tl|Str rightc|<string>|<count>}} - extract right-side of string | ||
* {{ | * {{Tl|Str len|<string>}} - get numeric length of string (can be over 300 long) | ||
<includeonly> | <includeonly> | ||
Revision as of 15:28, 11 October 2009
Usage
{{Str left|<string>|<count>}}
Gives the <count> substring of characters from the start of the string (the substring has length <count>).
If <count> is invalid or empty, an empty string is returned. If undefined, it defaults to 1.
Limitations
- Length to 500: The maximum substring stops at 500 long, yet gives no error message. Only 500 characters can be extracted even if the <string> is longer.
- Inexpensive (uses no other templates).
Examples
- {{Str left| lorem ipsum dolor sit amet | 10 }} → lorem ipsu
- {{Str left| lorem ipsum dolor sit amet | 1 }} → l
- {{Str left| lorem ipsum dolor sit amet | }} →
- {{Str left| lorem ipsum dolor sit amet }} → l
See also
- [[:<count>:Template:Trunc|{{<string>}}]] - truncate right-side of string
- [[:<count>:Template:Str right|{{<string>}}]] - extract remainder of string
- [[:<count>:Template:Str rightc|{{<string>}}]] - extract right-side of string
- {{<string>}} - get numeric length of string (can be over 300 long)