සැකිල්ල:Strfind short/doc
The Template:Strfind_short finds the location, in parameter {1} with length lenstr=15 (up to 99), of the string {2} with length {3}, using a simple, quick method. 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}} → 0
- {{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
- {{strfind short|abcdef|-|1}} → 0
- {{strfind short|abcdef|x|1}} → 0
- {{strfind short|abcdef|xyz|3}} → 0
Performance impact
සංස්කරණයThe operation of Template:Strfind_short was designed to run 4x times faster than other string-search templates; 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.
See also
සංස්කරණය- {{Str find}} - searches strings, but with expansion depth of 18 or more
Easy to use and efficient string length comparison templates:
- {{str ≥ len}} – To check if a string is "longer or equally long" vs. "shorter" than a given length.
- {{str ≤ len}} – To check if a string is "shorter or equally long" vs. "longer" than a given length.
- {{str ≠ len}} – To check if a string is "not equal" vs. "equal" to a given length.
- {{str ≤ ≥ len}} – To check all three of "shorter", "equal" and "longer" at the same time.
Much less efficient string length template:
- {{str len}} – Takes a string as parameter and returns its length. Can count up to 500 in length.
Technical stuff:
- mw:Help:Magic words – About
{{padleft:|}}
. - mw:Help:Extension:ParserFunctions – About
{{#ifeq:|||}}
etc.