Jump to content

Template:Str find/doc

From Wikipedia, the free encyclopedia

Usage

[edit]

{{Str find|text|sub_string}}

Returns the position of first appearance of sub_string in text.

  • The comparison is case sensitive.
  • Returns -1 if sub_string not found
  • Character position is 1 based (not 0 based as usual in calculations).
  • If sub_string is empty, this routine returns 1. This case will often have to be handled specially.

Examples

[edit]

In the examples, the string to be searched is Abcdefghijklm:

  • A; 1
  • a; -1
  • def; 4
  • klm; 11
  • zyx; -1

Examples with empty parameters:

  • empty;klm; -1
  • empty;empty; 1

TemplateData

[edit]
This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. See a monthly parameter usage report for Template:Str find in articles based on its TemplateData.

TemplateData for Str find

A template to find the numeric position of first appearance of ''sub_string'' in ''text''

Template parameters

ParameterDescriptionTypeStatus
Text1

The text to search within

Stringrequired
Sub_string2

The string to be searched within the text

Stringrequired

See also

[edit]