Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
PricePedia
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Template:Str left/doc
Template
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{used in system}} {{Documentation subpage}} <!-- Categories go where indicated at the bottom of this page, please; interwikis go to Wikidata (see also: [[Wikipedia:Wikidata]]). --> == Usage == : {{Template link expanded|Str left|<string>|<count>}} Gives the resultant <count> of characters ''creating a substring of characters'' from the start of the [[w:Trim (programming)|trimmed]] string (i.e. the substring returned will have length <count>, exclusive of leading whitespace characters, which are trimmed first before <count> is invoked). If <count> is invalid, empty or zero, 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 == :* <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | Lorem ipsum dolor sit amet | 10 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | Lorem ipsum dolor sit amet | 10 }} :*<code><nowiki>{{Str left| Lorem ipsum dolor sit amet | 4 }}</nowiki></code> → {{Str left| Lorem ipsum dolor sit amet | 4 }}, (note leading spaces trimmed!) :* <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | Lorem ipsum dolor sit amet | 1 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | Lorem ipsum dolor sit amet | 1 }} :* <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | Lorem ipsum dolor sit amet | 0 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | Lorem ipsum dolor sit amet | 0 }} :* <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | Lorem ipsum dolor sit amet | <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | Lorem ipsum dolor sit amet | }} :* <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | Lorem ipsum dolor sit amet <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | Lorem ipsum dolor sit amet }} :* <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | Lorem ipsum dolor sit amet | 40 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | Lorem ipsum dolor sit amet | 40 }} :* <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | àçé | 2 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | àçé | 2 }} :*: This example is demonstrating the safety of this template with the UTF-8 encoding (this should work now) : ===Examples of limitations=== All the limitations of use for this template and shown below are caused by the current implementation of the <nowiki>{{padleft:}}</nowiki> parser function used in this template, which does not filter its third parameter containing the characters used for padding a string to the specified length (it currently counts incorrectly the characters to extract from the padding string, and incorrectly measures its effective length; in addition this parameter is limited to 500 bytes). The following examples are demonstrating that this template does not interpret character entity references as the character they represent. It treats them as multiple characters and can leave them truncated. * <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | a&nbsp;c | 3 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | a c | 3 }} *: The output "a c" may have been intended, but the named character entity was truncated, leaving no length available for the final "c". * <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | a&#66;c | 3 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | aBc | 3 }} *: This should display "abc", but the named character entity was truncated, leaving no length available for the final "c". * <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | a c | 3 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | a c | 3 }} *: The result is correct, as expected. * <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | a&#32;c | 3 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | a c | 3 }} *: This last example should be equivalent to the previous one, but it is not. This template will erase nowiki tags without counting their length: * <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | a<nowiki/>bcd | 3 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | a<nowiki/>bcd | 3 }} *: Returns three characters as expected * <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | a<nowiki>E</nowiki>bcd | 3 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | a<nowiki>E</nowiki>bcd | 3 }} *: Returns three characters, but not aEb as might have been expected. * <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | a<nowiki/>bc | 10 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | a<nowiki/>bc | 10 }} *: Returns 10 characters as expected. HTML comments, and the "noinclude", "includeonly" and "onlyinclude" wiki markup tags are also ignored, because they are preprocessed in template parameters, before including it and substituting parameters: :* <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | a<noinclude/>bc | 3 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | a<noinclude/>bc | 3 }} :* <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | a<!-- comment -->bc | 3 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | a<!-- comment -->bc | 3 }} Note also that the specified length will cause the input string to be padded by repeating it, if this length is larger than the input string length: :* <code><nowiki>{{</nowiki> {{BASEPAGENAME}} | Abc. | 10 <nowiki>}}</nowiki></code> → {{ {{BASEPAGENAME}} | Abc. | 10 }} == Template data == {{TemplateData header}} <templatedata> { "description": "A template to give the <count> substring of characters from the start of the trimmed string ", "params": { "1": { "label": "String", "description": "The string to be trimmed and counted", "type": "string", "required": true }, "2": { "label": "Count", "description": "Gives the <count> substring of characters from the start of the trimmed string", "type": "number", "required": true } } } </templatedata> == See also == * [[Bugzilla:22555]] (historical; need for correcting padleft/padright functions and to provide better string-handling parser functions) {{String-handling templates |sub}} <includeonly>{{Sandbox other|| <!-- Categories go below this line, please; interwikis go to Wikidata, thank you! --> [[Category:String manipulation templates]] }}</includeonly>
Summary:
Please note that all contributions to PricePedia may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
PricePedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Aligned table
(
edit
)
Template:Div col
(
edit
)
Template:Div col/styles.css
(
edit
)
Template:Div col end
(
edit
)
Template:Documentation subpage
(
edit
)
Template:Hlist/styles.css
(
edit
)
Template:Main other
(
edit
)
Template:Mbox
(
edit
)
Template:Plainlist/styles.css
(
edit
)
Template:Sandbox other
(
edit
)
Template:Str left
(
edit
)
Template:String-handling templates
(
edit
)
Template:Strong
(
edit
)
Template:TemplateData header
(
edit
)
Template:Template link
(
edit
)
Template:Template link expanded
(
edit
)
Template:Template other
(
edit
)
Template:Template parameter usage
(
edit
)
Template:Terminate sentence
(
edit
)
Template:Tl
(
edit
)
Template:Used in system
(
edit
)
Template:Yesno
(
edit
)
Template:Yesno-no
(
edit
)
Module:Aligned table
(
edit
)
Module:Arguments
(
edit
)
Module:Check for unknown parameters
(
edit
)
Module:Effective protection level
(
edit
)
Module:High-use
(
edit
)
Module:Message box
(
edit
)
Module:Message box/configuration
(
edit
)
Module:Message box/ombox.css
(
edit
)
Module:Navbar
(
edit
)
Module:Navbar/configuration
(
edit
)
Module:Navbar/styles.css
(
edit
)
Module:Navbox
(
edit
)
Module:Navbox/configuration
(
edit
)
Module:Navbox/styles.css
(
edit
)
Module:Navbox with collapsible groups
(
edit
)
Module:String
(
edit
)
Module:TableTools
(
edit
)
Module:Template link general
(
edit
)
Module:Transclusion count
(
edit
)
Module:Transclusion count/data/S
(
edit
)
Module:Yesno
(
edit
)