Template:Strloc prefix/doc

The string-prefixer Template:Strloc prefix gets the prefix of a string up to a specified location, or the entire string when location is less than 1.

Template:Strloc prefix/doc

The string-prefixer Template:Strloc prefix gets the prefix of a string up to a specified location, or the entire string when location is less than 1.

Usage

{{Strloc prefix|<string1>|strloc=<n>}}

Returns the prefix of string1 up to location strloc=n, where n = 1 denotes the first character of the string. If strloc <= 0 then the entire string1 is the result. The parameter strloc can be a math formula, such as: strloc={{{len}}}-2, or strloc=abs(-2*5)+6.

Examples

The following show various uses:

  • {{Strloc prefix|abcdef|strloc=3}} → abc
  • {{Strloc prefix|abcdef|strloc=0}} → abcdef
  • {{Strloc prefix|My Title (film)|strloc= {{strfind_short|My Title (film)|(|1|lenstr={{strlen_quick|My Title (film)}}|}}-2}} → My Title
In the example with "{{strfind_short}}: the number for strloc was set by finding "(" in the
title. If there had been no parenthesis "(" then the result would get the entire title.

Limitations

The text extracted is subject to the limitations of parser functions {#ifexpr:} and {padleft:}. In particular, spaces around the prefixed string are dropped, and NOT counted, before or after:

  • {{Strloc prefix| Title here |strloc=9}}   → "Title her"
  • {{Strloc prefix| Title here |strloc=0}}   → "Title here"

Spaces embedded within the prefix string are real spaces (NOT "&#32;"), and any accented or special characters can be used in the 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, replacing the first occurrence of a specified string, with another string. Requires a match.
  • {{Str repc}} — Returns the string, replacing the first occurrence of a specified string, with another string, if there is one.
  • {{Repeat}} — Repeat character string n times


Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.