Template:String-handling templates: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Roberts7
+ Str find0
Ookami (talk | contribs)
m 104 revisions imported
 
(82 intermediate revisions by 28 users not shown)
Line 1: Line 1:
[[Trim (programming)|Trimming]] templates:
{{Navbox with collapsible groups
| name = String-handling templates
| state = {{{state|expanded}}}
| bodyclass = plainlist
| title = String-handling templates
| selected = {{{selected|{{{expanded|{{{1|}}}}}}}}}


* {{tl|Trunc}} – To trim down to a specified number of characters.
<!---------------------- Trimming ------------------------->
* {{tl|Str left}} – To trim down to a specified number of characters, or duplicate the string to a specified number.
| abbr1 = trim
* {{tl|Str crop}} – To crop a specified number of characters off the end.
| sect1 = [[Trimming (computer programming)|Trimming]]
* {{tl|Chop head and tail}} — To crop a specified number of characters off the beginning and end.
| content1 =
* {{tl|Trim}} — To trim any leading or trailing whitespace.
{{Navbox |child
* {{tl|First word}} — To trim down to the first space.
* {{tl|Remove first word}} — To remove anything before the first space.
* {{tl|Str letter/trim}} — To trim down to the beginning letters.
* {{tl|Str number/trim}} — To trim down to the beginning numbers.
* {{tl|Title without disambig}} — To trim off any parenthesis text at the end of a string.
* {{tl|Title disambig text}} – Returns text in parenthesis at the end of a string.
* {{tl|Str right}} — To trim the first specified number of characters.
* {{tl|Str rightc}} — To trim the first specified number of characters, returns a parameter if the string is empty.
* {{tl|Str rightmost}} — To trim down to the last specified number of characters.
* {{tl|Str sub}} — To trim down to a specified number, starting at a given number from the left, less than 50.
* {{tl|Substr any}} — To trim down to a specified number, starting at a given number from the left, less than 50, can extract accented letters.
* {{tl|Str sub long}} — To trim down to a specified number, starting at a given number from the left, less than 100.


Inserting strings:
  | group1 = By counting
  | list1 =
  {{Aligned table |fullwidth=on |style=text-align:left; |col1width=50%;
    | {{Aligned table |style=padding-right:2.5em;
      |col1style=width:12.5em;text-align:right;white-space:nowrap;padding-right:0.75em;
      | {{tl|str mid}}      | To return a substring specified by position and length.
      | {{tl|trunc}}        | To trim down to a specified number of characters.
      | {{tl|str left}}      | To trim down to a specified number of characters or duplicate the string to a specified number.
      | {{tl|str crop}}      | To crop a specified number of characters off the end.
      | {{tl|chop head and tail}} | To crop a specified number of characters off the beginning and end.
      }}
    | {{Aligned table
      |col1style=width:12.5em;text-align:right;white-space:nowrap;padding-right:0.75em;
      | {{tl|str right}}    | To trim the first specified number of characters.
      | {{tl|str rightc}}    | To return a number of characters from the end, returns a parameter if the string is empty.
      | {{tl|str rightmost}} | To trim down to the last specified number of characters.
      | {{tl|str sub old}}  | To trim down to a specified number, starting at a given number from the left.
      | {{tl|str sub new}}  | Select a substr based on starting and ending index.
      | {{tl|str index}}    | Returns a given character from a string, but not accented letters.
      | {{tl|Plain text}}, {{tl|Nowiki}}    | Strips wikicode from a string.
  }} }}


* {{[[Template:Strloc insert|Strloc insert]]}} - Inserts a string at character location strloc, or appends if strloc<=0.
  | group2 = By checking
* {{[[Template:Strloc prefix|Strloc prefix]]}} - Extracts string prefix up to location strloc, or whole string if strloc<=0.
  | list2 =
* {{[[Template:Str rep|Str rep]]}} — Returns the string, replacing the first occurrence of a specified string, with another string. Requires a match.
  {{Aligned table |fullwidth=on |style=text-align:left; |col1width=50%;
* {{[[Template:Str repc|Str repc]]}} — Returns the string, replacing the first occurrence of a specified string, with another string, if there is one.
    | {{Aligned table |style=padding-right:2.5em;
      |col1style=width:12.5em;text-align:right;white-space:nowrap;padding-right:0.75em;
      | {{tl|trim}}               | To trim any leading or trailing whitespace
      | {{tl|str letter/trim}}    | To trim down to the beginning letters.
      | {{tl|str number/trim}}     | To trim down to the beginning numbers.
      | {{tl|trim brackets}}      | To trim any leading or trailing square brackets.
      | {{tl|trim quotes}}        | To trim leading or trailing matching quotes.
      }}
    | {{Aligned table
      |col1style=width:12.5em;text-align:right;white-space:nowrap;padding-right:0.75em;
      | {{tl|first word}}         | To trim down to the first space.
      | {{tl|remove first word}}  | To remove anything before the first space.
      | {{tl|last word}}          | To trim down from the last space.
      | {{tl|remove last word}}   | To remove anything after the last space.
  }} }}


Analyzing strings:
  | group3 = Dedicated
  | list3 =
  {{Aligned table |fullwidth=on |style=text-align:left; |col1width=50%;
    | {{Aligned table |style=padding-right:2.5em;
      |col1style=width:12.5em;text-align:right;white-space:nowrap;padding-right:0.75em;
      | {{tl|delink}}, {{tl|trim brackets}}              | Removes wikilink brackets (wikicode); ''all'' or ''outer only''.
      | {{tl|remove file prefix}}  | Removes "File:" (or "Image:") from filenames.
      | {{tl|PAGENAMEBASE}}        | To trim off any parenthesis text at the end of a string (disambiguation).
      | {{tl|title disambig text}} | Returns text in parentheses at the end of a string (disambiguation).
      }}
    | {{Aligned table
      |col1style=width:12.5em;text-align:right;white-space:nowrap;padding-right:0.75em;
      | {{tl|WikiProjectbasename}} | Removes "WikiProject" from a pagename.
      | {{tl|remove unranked}}    | Removes the string "unranked_" from the left of a string (taxonomy).
      | {{tl|ship prefix}}        | Returns the length of a ship's name prefix, if listed (ship names).
      | {{tl|title year}}          | Returns the 4-digit year from a pagename, if any.
      | {{tl|title decade}}        | Returns the 4-digit decade (e.g. "1740s") from a pagename, if any.
  }} }}
}}


* {{tl|Str endswith}} – To check if a string ends with a given string.
<!----------- Insertion, replacement, length -------------->
* {{tl|Str find}} – Returns the numerical location of a given string in a string, up to 50 characters.
| abbr2 = IRL
* {{tl|Str find long}} – Returns the numerical location of a given string in a string, up to 80 characters.
| sect2 = Insertion, replacement and length
* {{tl|Strfind short}} – Searches for a short string in a longer (up to 99 char) string. Performs faster than {{tl|str find}}
| content2 =
* {{tl|Str find0}} – Very fast zero-based substring search with string support up to 90 characters.
{{Aligned table |style=margin:0 auto 0;text-align:left;
* {{tl|Str sub find}} – Searches a substring in a string at the given offset.
  | <!---(Insertion, replacement)--->
* {{tl|Str index}} Returns a given character from a string, but not accented letters.
    {{Aligned table |style=padding-right:2.5em;
* {{tl|Str index any}} Returns a given character from a string, but not a space.
    |col1style=text-align:right;white-space:nowrap;padding-right:0.75em;
* {{tl|Chr}} – Returns a given character from a string, including a space.
    | {{tl|strloc insert}} | Inserts a string at character location strloc, or appends if strloc<{{=}}0.
* {{tl|Str len}} Returns a string's length. Can count up to 500 characters.
    | {{tl|loop}}         | Repeat character string a specified number of times.
* {{tl|Strlen quick}} – Gets string length quickly (better performance), up to 70 long.
    | {{tl|replace}}       | Returns the string, after replacing ''all'' occurrences of a specified string with another string.
* {{tl|Strlen short}} – Gets length of short strings (1-50), using only 2 expansion levels.
    | {{tl|str rep}}       | Returns the string, after replacing the first occurrence of a specified string with another string.
* {{tl|Str letter}} — Returns the number of letters that begin a string.
    | {{tl|digits}}       | Returns the string, after removing all characters that are not digits 0–9
* {{tl|Str number}} — Returns the number of numbers that begin a string.
    }}
* {{tl|Ship prefix}} — Returns the length of a ship name prefix, if listed.
  |  <!---(Length)--->
    {{Aligned table
    |col1style=text-align:right;white-space:nowrap;padding-right:0.75em;
    | {{tl|str len}}       | Returns a string's length.
    | {{tl|str ≥ len}}     | To check if a string is "longer or equally long" or "shorter" than a given length.
    | {{tl|str ≤ len}}     | To check if a string is "shorter or equally long" or "longer" than a given length.
    | {{tl|str ≠ len}}     | To check if a string is "not equal" or "equal" to a given length.
    | {{tl|str ≤ ≥ len}}   | To check if a string is "shorter", "equal", or "longer" than a given length.
}} }}


String length comparison templates:
<!----------------- Analysis, technical ------------------->
| abbr3 = anlys/tech
| sect3 = Analysis and technical
| content3 =
{{Aligned table |style=margin:0 auto 0;text-align:left;
  |  <!---(Analysis)--->
    {{Aligned table |style=padding-right:2.5em;
    |col1style=text-align:right;white-space:nowrap;padding-right:0.75em;
    | {{tl|str endswith}}  | To check if a string ends with a given string.
    | {{tl|str find}}<br/>{{tl|strfind short}} |style2.2=vertical-align:middle;| Returns the numerical location of a given string in a string.
    | {{tl|str find0}}    | Zero-based substring search.
    | {{tl|str sub find}}  | Searches a substring in a string at the given offset.
    | {{tl|str letter}}    | Returns the number of letters that begin a string.
    | {{tl|str number}}    | Returns the number of numbers that begin a string.
    | {{tl|str gtr str}}  | Compares two strings for alphabetical order, and returns a value accordingly.
    }}
  |  <!---(Analysis cont'd)--->
    {{Aligned table
    |col1style=text-align:right;white-space:nowrap;padding-right:0.75em;
    | {{tl|ASCII code}}    | Returns the ASCII value of a single character.
    | {{tl|a or an}}      | Takes a noun and produces the appropriate indefinite article, based on whether the first letter is a vowel.
    | {{tl|Isnumeric}}    | Returns number when true, blank when not numeric.
    | &nbsp; | &nbsp;
    | {{tl|Count on page}} | Counts how many times a string is used on a page
    | {{tl|String on page}}| Finds if yes/no a string is used on a page
    | &nbsp; | &nbsp;
    <!---(Technical)--->
    | [[mw:Help:Magic words|...Magic words]] | {{noitalic|About <code><nowiki>{{padleft:&#124;}}</nowiki></code>.}}
    | [[mw:Help:Extension:ParserFunctions|...ParserFunctions]] | {{noitalic|About <code><nowiki>{{#titleparts:&#124;}}, {{#expr:&#124;}}, {{#ifeq:&#124;}}, </nowiki></code> etc.}}
}} }}


* {{tl|Str ≥ len}} – To check if a string is "longer or equally long" or "shorter" than a given length.
| group12 = Generic: [[:Module:String]]
* {{tl|Str ≤ len}} – To check if a string is "shorter or equally long" or "longer" than a given length.
* {{tl|Str ≠ len}} – To check if a string is "not equal" or "equal" to a given length.
* {{tl|Str ≤ ≥ len}} – To check if a string is "shorter", "equal", or "longer" than a given length.


[[Wikipedia:Template sandbox and test cases|Sandboxes and test cases]]:
<!--------------------- (disabled) ------------------------>
<!----
| group12 = Feature requests
| list12 =
* [[bugzilla:6455]] – Set $wgPFEnableStringFunctions = true on WMF wikis
* [[bugzilla:26092]] – Enable or install string parsing wikimarkup functionality on WMF wikis


<!----Not in a navbox:
| group13 = [[Wikipedia:Template sandbox and test cases|Sandboxes, testcases]]
| list13 =
* {{tl|Str find/sandbox}}
* {{tl|Str find/sandbox}}
* {{tl|Str index/getchar/sandbox}}
* {{tl|Str index/getchar/sandbox}}
Line 67: Line 154:
* {{tl|Str ≠ len/sandbox}}
* {{tl|Str ≠ len/sandbox}}
* {{tl|Str ≠ len/testcases}}
* {{tl|Str ≠ len/testcases}}
----->


Technical stuff:
<!----------------------- below --------------------------->
| belowclass = hlist
| below =
* [[:Category:String manipulation templates]]
* [[m:Category:String templates]]
* [[:commons:Category:String manipulation templates]]


* [[mw:Help:Magic words]] – About <code><nowiki>{{padleft:|}}</nowiki></code>.
| tracking = no <!--(keep all these string templates (by /doc pages) out of the tracking category)-->
* [[mw:Help:Extension:ParserFunctions]] – About <code><nowiki>{{#titleparts:|}}, {{#expr:|}}, {{#ifeq:|}}, </nowiki></code> etc.


Feature requests:
}}<noinclude>{{Documentation}}</noinclude>
 
* [[bugzilla:6455]] - Set $wgPFEnableStringFunctions = true on WMF wikis
* [[bugzilla:26092]] - Enable or install string parsing wikimarkup functionality on WMF wikis
<noinclude>

Latest revision as of 14:49, 3 September 2020