Template:Str left/doc: Difference between revisions
Template page
More actions
m iw |
|||
| Line 15: | Line 15: | ||
=== Examples === | === Examples === | ||
* <tt><nowiki>{{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | 10 }}</nowiki></tt> → {{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | 10 }} | |||
* <tt><nowiki>{{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | 1 }}</nowiki></tt> → {{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | 1 }} | |||
* <tt><nowiki>{{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | 0 }}</nowiki></tt> → {{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | 0 }} | |||
* <tt><nowiki>{{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | }}</nowiki></tt> → {{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | }} | |||
* <tt><nowiki>{{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet }}</nowiki></tt> → {{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet }} | |||
* <tt><nowiki>{{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | 40 }}</nowiki></tt> → {{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | 40 }} | |||
* <tt><nowiki>{{ {{<noinclude>BASE</noinclude>PAGENAME}} | àçé | 2 }}</nowiki></tt> → {{Str left| àçé | 2 }} | |||
: This example is demonstrating the safety of this template with the UTF-8 encoding (this should work now) : | |||
== Bugs or limitations == | |||
*<tt><nowiki>{{ | The following examples are demonstrating that this template is not safe with HTML character entity references (bug or limitation of the <nowiki>{{padleft:}}</nowiki> parser function used in this template) : | ||
*<tt><nowiki>{{ | * <tt><nowiki>{{ {{<noinclude>BASE</noinclude>PAGENAME}} | a&nbsp;c | 3 }}</nowiki></tt> → {{ {{<noinclude>BASE</noinclude>PAGENAME}} | a c | 3 }} | ||
*<tt><nowiki>{{ | * <tt><nowiki>{{ {{<noinclude>BASE</noinclude>PAGENAME}} | a&#66;c | 3 }}</nowiki></tt> → {{ {{<noinclude>BASE</noinclude>PAGENAME}} | aBc | 3 }} | ||
*<tt><nowiki>{{ | * <tt><nowiki>{{ {{<noinclude>BASE</noinclude>PAGENAME}} | a c | 3 }}</nowiki></tt> → {{ {{<noinclude>BASE</noinclude>PAGENAME}} | a c | 3 }} | ||
* <tt><nowiki>{{ {{<noinclude>BASE</noinclude>PAGENAME}} | a&#32;c | 3 }}</nowiki></tt> → {{ {{<noinclude>BASE</noinclude>PAGENAME}} | a c | 3 }} | |||
*: This example should be equivalent to the previous one, but it is not. | |||
=== See also === | === See also === | ||
Revision as of 09:19, 10 October 2010
Usage
{{Str left|<string>|<count>}}
Gives the <count> substring of characters from the start of the trimmed 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
- {{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | 10 }} → Lorem ipsu
- {{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | 1 }} → L
- {{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | 0 }} →
- {{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | }} →
- {{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet }} → L
- {{ {{<noinclude>BASE</noinclude>PAGENAME}} | Lorem ipsum dolor sit amet | 40 }} → Lorem ipsum dolor sit ametLorem ipsum do
- {{ {{<noinclude>BASE</noinclude>PAGENAME}} | àçé | 2 }} → àç
- This example is demonstrating the safety of this template with the UTF-8 encoding (this should work now) :
Bugs or limitations
The following examples are demonstrating that this template is not safe with HTML character entity references (bug or limitation of the {{padleft:}} parser function used in this template) :
- {{ {{<noinclude>BASE</noinclude>PAGENAME}} | a c | 3 }} → a&n
- {{ {{<noinclude>BASE</noinclude>PAGENAME}} | aBc | 3 }} → a&#
- {{ {{<noinclude>BASE</noinclude>PAGENAME}} | a c | 3 }} → a c
- {{ {{<noinclude>BASE</noinclude>PAGENAME}} | a c | 3 }} → a&#
- This example should be equivalent to the previous one, but it is not.
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)