• Start
  • Zufällige Seite
  • Anmelden
  • Einstellungen
  • Über Korstipedia
  • Haftungsausschluss
Korstipedia

Vorlage:Str left

  • Sprache
  • Beobachten
  • Quelltext anzeigen
Template documentation[view] [edit] [history] [purge]
WarningThis template is used in system messages, and on approximately 918.000 pages, or roughly 473196% of all pages.
Changes to it can cause immediate changes to the Wikipedia user interface.
To avoid major disruption and server load, any changes should be tested in the template's /sandbox or /testcases subpages, or in your own user subpage. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them.


Inhaltsverzeichnis

  • 1 Usage
  • 2 Limitations
  • 3 Examples
    • 3.1 Examples of limitations
  • 4 Template data
  • 5 See also

Usage

{{Str left|<string>|<count>}}

Gives the resultant <count> of characters creating a substring of characters from the start of the 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

  • {{ Str left | Lorem ipsum dolor sit amet | 10 }} → Lorem ipsu
  • {{Str left|   Lorem ipsum dolor sit amet | 4 }} → Lore, (note leading spaces trimmed!)
  • {{ Str left | Lorem ipsum dolor sit amet | 1 }} → L
  • {{ Str left | Lorem ipsum dolor sit amet | 0 }} →
  • {{ Str left | Lorem ipsum dolor sit amet | }} →
  • {{ Str left | Lorem ipsum dolor sit amet }} → L
  • {{ Str left | Lorem ipsum dolor sit amet | 40 }} → Lorem ipsum dolor sit ametLorem ipsum do
  • {{ Str left | àçé | 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 {{padleft:}} 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.

  • {{ Str left | a&nbsp;c | 3 }} → a&n
    The output "a c" may have been intended, but the named character entity was truncated, leaving no length available for the final "c".
  • {{ Str left | a&#66;c | 3 }} → a&#
    This should display "abc", but the named character entity was truncated, leaving no length available for the final "c".
  • {{ Str left | a c | 3 }} → a c
    The result is correct, as expected.
  • {{ Str left | a&#32;c | 3 }} → a&#
    This last example should be equivalent to the previous one, but it is not.

This template will erase nowiki tags without counting their length:

  • {{ Str left | a<nowiki/>bcd | 3 }} → abc
    Returns three characters as expected
  • {{ Str left | a<nowiki>E</nowiki>bcd | 3 }} → abc
    Returns three characters, but not aEb as might have been expected.
  • {{ Str left | a<nowiki/>bc | 10 }} → abcabcabca
    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:

  • {{ Str left | a<noinclude/>bc | 3 }} → abc
  • {{ Str left | a<!-- comment -->bc | 3 }} → abc

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:

  • {{ Str left | Abc. | 10 }} → Abc.Abc.Ab

Template data

This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. See a monthly parameter usage report for Template:Str left in articles based on its TemplateData.

TemplateData for Str left

<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)
  • v
  • t
  • e
String-handling templates (help page)
Substring (select chunk of string by its position)
{{str sub new}} Select a substring based on starting and ending index counted in either direction.
{{str left}} Keep the first N characters of a string, or duplicate it to N characters.
{{str crop}} Return all but the last N characters of a string.
{{str index}} Return the N-th character of a string.
{{str right}} Return substring starting at N-th character to end of string.
{{str rightc}} Return the last N characters of a string; or a given value if empty.
{{str sub old}} Return substring of given length starting at N-th character.
Trimming (select/remove chunk of string by character type)
{{trim}} Trim any leading or trailing whitespace
{{str letter/trim}} Trim down to the beginning letters.
{{str number/trim}} Trim down to the beginning numbers.
{{trim brackets}} Trim any leading or trailing square brackets.
{{trim quotes}} Trim leading or trailing matching quotes.
{{trim leading}} Trim up to six instances of specified <prefix>.
{{string split}} Extract a short string from a long string.
{{first word}} Trim down to the first space.
{{remove first word}} Remove anything before the first space.
{{last word}} Trim down from the last space.
{{remove last word}} Remove anything after the last space.
Select/remove specific item from string
{{delink}}, {{trim brackets}} Removes wikilink brackets (wikicode); all or outer only.
{{Plain text}} Removes wikicode (formatting and brackets)
{{PAGENAMEBASE}} Trim off any parenthesis text at the end of a string (disambiguation).
{{title disambig text}} Returns text in parentheses at the end of a string (disambiguation).
{{WikiProjectbasename}} Removes "WikiProject" from a pagename.
{{ship prefix}} Returns the length of a ship's name prefix, if listed (ship names).
{{title year}} Returns the 3-or-4-digit year from a pagename, if any.
{{title decade}} Returns the 4-digit decade (e.g. "1740s") from a pagename, if any.
{{title number}} Returns any number from a pagename.
Insertion, replacement and length
{{loop}} Repeat character string a specified number of times.
{{replace}} Returns the string, after replacing all occurrences of a specified string with another string.
{{str rep}} Returns the string, after replacing the first occurrence of a specified string with another string.
{{digits}} Returns the string, after removing all characters that are not digits 0–9
{{Nowiki}} Displays wikitext as plain text.
{{str len}} Returns a string's length.
{{str ≥ len}} Check if a string is "longer or equally long" or "shorter" than a given length.
{{str ≤ len}} Check if a string is "shorter or equally long" or "longer" than a given length.
{{str ≠ len}} Check if a string is "not equal" or "equal" to a given length.
Analysis and searching
{{str startswith}}
{{str endswith}}
Check if a string starts or ends with a given string.
{{str find}}, {{strfind short}} Returns the numerical location of a given string in a string.
{{in string}} Returns optional string when given string is not found
{{str count}} Count the number of occurrences of a pattern within a string.
{{a or an}} Takes a noun and produces the appropriate indefinite article, based on whether the first letter is a vowel.
{{Array}} Array manipulation and retrieval.
{{Isnumeric}} Returns number when true, blank when not numeric.
{{str letter}} Returns the number of letters that begin a string.
{{str number}} Returns the number of numbers that begin a string.
Modules and built-in functions
  • Module:String, Module:String2, Module:Ustring, Module:Text, wikitext handling: modules that together contain most necessary string functions.
  • Magic words: About {{padleft:|}}, {{lc:|}}, {{formatnum:|}} etc.
  • ParserFunctions: About {{#titleparts:|}}, {{#expr:|}}, {{#ifeq:|}}, etc.
  • Category:String manipulation templates
    • Commons
    • MediaWiki
    • Meta-Wiki
    • Wikidata
  • Category:String manipulating modules
  • The above documentation is transcluded from Vorlage:Str left/doc. (edit | history)
    Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages.
    Add categories to the /doc subpage. Subpages of this template.
    Abgerufen von „https://wiki.korsti.pp.ua:443/?title=Vorlage:Str_left&oldid=240“
    Zuletzt bearbeitet am 14. Januar 2024 um 01:12

    Sprachen

      Diese Seite ist nicht in anderen Sprachen verfügbar.

      Korstipedia
      • Diese Seite wurde zuletzt am 14. Januar 2024 um 01:12 Uhr bearbeitet.
      • Der Inhalt ist verfügbar unter der Lizenz Creative Commons „Zero“ (Gemeinfreiheit), sofern nicht anders angegeben.
      • Datenschutz
      • Über Korstipedia
      • Haftungsausschluss
      • Klassische Ansicht