Template talk:Str find

Whitespace
These examples:

results in: ,, ,.

Is there a way to make it work with whitespace? Fulcanelli (talk) 08:13, 30 April 2009 (UTC)


 * I've fixed it to work for case 1. I just knew when they changed str_len to ignore whitespace it would mess other things up.  Dragons flight (talk) 13:43, 30 April 2009 (UTC)
 * Thanks a lot! Fulcanelli (talk) 02:44, 2 May 2009 (UTC)

Usage
"Only searches first 50 characters of text. Returns -1 if sub_string not found in first 80 characters."; that does not seem correct... - Erik Baas (talk) 15:52, 24 June 2010 (UTC)

Rewrite to avoid 16 levels of 41 depth limit
I have written a simplified variation, as Template:Strfind_short, to use far less in wiki-server resources to find the same strings. The new variation uses only 6 levels of the expansion depth limit, while the older template {str_find} uses (an almost unbelievable) 22 levels, explained due to {str_find} invoking str_len which uses 9 levels alone. For example the string "45" is located at position 4 in "123456789", however, {str_find} cannot process that case when nested 23 deep of the total 41 expansion levels, so it reports "-1" instead of the correct position as 4: When nested only 18 deep, then {str_find} can finally match "45" at position 4, without exceeding the expansion-depth limit. However, new template strfind_short can process the same search for "45" when nested inside 34 other templates, at 16 levels deeper than {str_find} requires: This improved efficiency requires the length of the 2nd string to be passed into the search, or alternatively, a page can use quick template strlen_short to get the string length to pass. I am still testing the new strfind_short to verify it can handle other strings correctly. -Wikid77 (talk) 18:58, 28 December 2010, revised to fit as 18-nested {str_find} 02:30, 19 November 2012 (UTC)
 * Nest 23 + {str_find|123456789|45|2}:
 * Nest 23 + {str_find|123456789|45|2}: -1
 * Nest 18 + {str_find|123456789|45|2}:
 * Nest 34 + {strfind_short|123456789|45|2}:
 * {&#123;strfind_short|abcddeabcde-abcdeabcde|cde|3}} &rarr;
 * {&#123;strfind_short|abCDdeabeRTEert|e|1}} &rarr;

Test cases
Here are some test cases: All correct?--Lashuto (talk) 02:31, 10 March 2011 (UTC)
 * = 1
 * = -1
 * = -1
 * = 1
 * = 2
 * = 2

Testing




Bug with this template
You are invited to join the discussion at Wikipedia:Village pump (technical) § String find bug. &#123;{u&#124; Sdkb  }&#125;  talk 23:10, 1 December 2021 (UTC)