Template:Strfind short/doc

The Template:Strfind_short finds the location, in parameter {1} with length lenstr=15 (up to 99), of the text string {2} with length {3}. It uses a simple, quick method to compare the strings. If the string is not found, the result is zero (0), indicating no match. The parameter lenstr can be shorter than the actual 1st string, to stop the search earlier (and faster). The template was designed to use only 5 levels of expansion depth, rather than 18 or more levels as in other string-searching templates.

Usage:  {{strfind short|abcdef|bcd|3}}       → 2
{{strfind short|123456789.|45|2}} → 4
{{strfind short|x+2.437-6|2.43|4}} → 3
{{strfind short|:***abcd**|*ab| {{strlen_short|*ab}} }} → 4

If the length of the substring {2} is not known, or changes often, then the extra template {strlen_quick} can be used as: {{strlen_quick|{{{2}}} }}, to determine the length of string 2, quickly.

Examples

The following are examples:

  • {{strfind short|abcdef|bcd|3}}       → 2
  • {{strfind short|Fast Forward (film)|(|1}}       → 14
  • {{strfind short|Fast Forward Longer (film)|(|1}} → 21
  • {{strfind short|Fast Forward Longer (film)|(|1|lenstr=26}} → 21
  • {{strfind short|A Funny Thing Happened on the Way to the Forum (film)|(|1|lenstr=53}} → 48

Performance impact

The operation of Template:Strfind_short was designed to run 4x times faster than other string-search templates, and use only 5 levels of expansion depth (not 18). However, it typically runs 20x times faster (or shorter) for strings up to 15 characters long. The post-expand include size averages about 300 bytes (rather than 6,000 bytes for other string-search templates). It can be used over 5,000 times per page (compared to only 350 times for other search templates). For strings over 50 long, it will use more resources, due to processing strings larger than other templates had allowed.

  • {{Str find}} – Returns the numerical location of a given string in a string, up to 50 characters.
  • {{Str find long}} – Returns the numerical location of a given string in a string, up to 80 characters.
  • {{Strfind short}} – Searches for a short string in a longer (up to 99 char) string. Performs faster than {{str find}}
  • {{Str index}} – Returns a given character from a string, but not accented letters.
  • {{Str len}} – Returns a string's length. Can count up to 500 characters.
  • {{Strlen quick}} – Gets string length quickly (better performance), up to 70 long.
  • {{Strlen short}} – Gets length of short strings (1-50), using only 2 expansion levels.


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.