Jump to content

Template talk:Str find

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
(Redirected from Template talk:Str find/doc)

Whitespace

[edit]

These examples:

{{str find|test test| }}
{{str find|test test| }}
{{str find|test test|2= }}
{{str find|test test|2= }}

results in: 5, -1, 1, -1.

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

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)[reply]
Thanks a lot! Fulcanelli (talk) 02:44, 2 May 2009 (UTC)[reply]

Usage

[edit]

"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)[reply]

Rewrite to avoid 16 levels of 41 depth limit

[edit]

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:

: Nest 23 + {str_find|123456789|45|2}: <!--
-->{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x
|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x
|{{1x|{{1x|{{1x
|{{str_find|123456789|45|2}}
}}}} }}}} }}}} }}}} }}}}  }}}} }}}} }}}} }}}} }}}}
}}}} }}
Nest 23 + {str_find|123456789|45|2}: -1
Nest 18 + {str_find|123456789|45|2}: 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:

Nest 34 + {strfind_short|123456789|45|2}: 4


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.

{{strfind_short|abcddeabcde-abcdeabcde|cde|3}} → 9
{{strfind_short|abCDdeabeRTEert|e|1}} → 6

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)[reply]

Test cases

[edit]

Here are some test cases:

  • 1 = 1
  • -1 = -1
  • -1 = -1
  • 1 = 1
  • 2 = 2
  • 2 = 2

All correct?--Lashuto (talk) 02:31, 10 March 2011 (UTC)[reply]

Testing

[edit]
  • {{str_find}} = 1
  • {{str_find|}} = 1
  • {{str_find||}} = 1
  • {{str_find|Bob|}} = 1
  • {{str_find||Bob}} = -1
  • {{str_find|Bob|Joe}} = -1
  • {{str_find|BobBob|bB}} = 3
  • {{str_find|Bob|B|}} = 1
  • {{str_find|Bob|o|}} = 2
  • {{str_find|Bob|b|}} = 3
  • {{str_find|o|Bob}} = -1
  • {{str_find| Bob |o}} = 2
  • {{str_find| Bob Jones |b J}} = 3
  • {{str_find|aaa aaa| a}} = 4
  • {{str_find|aaa aaa|a }} = 3
  • {{str_find|높지만 급격히|만}} = 3
  • {{str find|test test| }} = 5
  • {{str find|test test| }} = -1
  • {{str find|test test|2= }} = 1
  • {{str find|test test|2= }} = -1

  • {{str_find/sandbox}} = 1
  • {{str_find/sandbox|}} = 1
  • {{str_find/sandbox||}} = 1
  • {{str_find/sandbox|Bob|}} = 1
  • {{str_find/sandbox||Bob}} = -1
  • {{str_find/sandbox|Bob|Joe}} = -1
  • {{str_find/sandbox|BobBob|bB}} = 3
  • {{str_find/sandbox|Bob|B|}} = 1
  • {{str_find/sandbox|Bob|o|}} = 2
  • {{str_find/sandbox|Bob|b|}} = 3
  • {{str_find/sandbox|o|Bob}} = -1
  • {{str_find/sandbox| Bob |o}} = 2
  • {{str_find/sandbox| Bob Jones |b J}} = 3
  • {{str_find/sandbox|aaa aaa| a}} = 4
  • {{str_find/sandbox|aaa aaa|a }} = 3
  • {{str_find/sandbox|높지만 급격히|만}} = 3
  • {{str find/sandbox|test test| }} = 5
  • {{str find/sandbox|test test| }} = -1
  • {{str find/sandbox|test test|2= }} = 1
  • {{str find/sandbox|test test|2= }} = -1

Bug with this template

[edit]

 You are invited to join the discussion at Wikipedia:Village pump (technical) § String find bug. {{u|Sdkb}}talk 23:10, 1 December 2021 (UTC)[reply]