{{fbdoc item="title" value="INSTR"}}----
Locates the first occurrence of a substring or character within a string

{{fbdoc item="syntax"}}##
	[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Instr** ( [[KeyPgByref|byref]] //str// [[KeyPgAs|as]] [[KeyPgConstQualifier|const]] [[KeyPgString|string]],  [ **Any** ] [[KeyPgByref|byref]] //substring// [[KeyPgAs|as]] [[KeyPgConstQualifier|const]] [[KeyPgString|string]] ) [[KeyPgAs|as]] [[KeyPgInteger|integer]]
	[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Instr** ( [[KeyPgByref|byref]] //str// [[KeyPgAs|as]] [[KeyPgConstQualifier|const]] [[KeyPgWstring|wstring]], [ **Any** ] [[KeyPgByref|byref]] //substring// [[KeyPgAs|as]] [[KeyPgConstQualifier|const]] [[KeyPgWstring|wstring]] ) [[KeyPgAs|as]] [[KeyPgInteger|integer]]
	[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Instr** ( [[KeyPgByval|byval]] //start// [[KeyPgAs|as]] [[KeyPgInteger|integer]], [[KeyPgByref|byref]] //str// [[KeyPgAs|as]] [[KeyPgConstQualifier|const]] [[KeyPgString|string]], [ **Any** ] [[KeyPgByref|byref]] //substring// [[KeyPgAs|as]] [[KeyPgConstQualifier|const]] [[KeyPgString|string]] ) [[KeyPgAs|as]] [[KeyPgInteger|integer]]
	[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Instr** ( [[KeyPgByval|byval]] //start// [[KeyPgAs|as]] [[KeyPgInteger|integer]], [[KeyPgByref|byref]] //str// [[KeyPgAs|as]] [[KeyPgConstQualifier|const]] [[KeyPgWstring|wstring]], [ **Any** ] [[KeyPgByref|byref]] //substring// [[KeyPgAs|as]] [[KeyPgConstQualifier|const]] [[KeyPgWstring|wstring]] ) [[KeyPgAs|as]] [[KeyPgInteger|integer]]
##
{{fbdoc item="usage"}}##
	//first// = **Instr**( [ //start//, ] //str//, [ **Any** ] //substring// )
##
{{fbdoc item="param"}}
	##//str//##
		The string to be searched.
	##//substring//##
		The substring to find.
	##//start//##
		The position in ##//str//## at which the search will begin. The first character starts at position 1.

{{fbdoc item="ret"}}
	The position of the first occurrence of ##//substring//## in ##//str//##.

{{fbdoc item="desc"}}
	Locates the position of the first occurrence of a substring or character within a string. In the first form of ##**Instr**## (without ##//start//## parameter), the search begins at the first character.
	
	Zero (0) is returned if: either ##//substring//## is not found, either ##//str//## or ##//substring//## are empty strings, or ##//start//## < 1.
	
	If the ##**Any**## keyword is specified, ##**Instr**## returns the first occurrence of any character in ##//substring//##.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/strings/instr.bas"}}%%(freebasic)
' It will return 4
Print InStr("abcdefg", "de")

' It will return 0
Print InStr("abcdefg", "h")

' It will search for any of the characters "f", "b", "c", and return 2 as "b" is encountered first
Print InStr("abcdefg", Any "fbc")
%%
{{fbdoc item="filename" value="examples/manual/strings/instr2.bas"}}%%(freebasic)
dim test as string
dim idx as integer

test = "abababab"
idx = instr(test, "b")

do while idx > 0 'if not found loop will be skipped
	print """b"" at " & idx
	idx = instr(idx + 1, Test, "b")
loop
%%
<<'A Unicode example:
dim text as wstring*20
text = "&#1055;&#1088;&#1080;&#1074;&#1077;&#1090;, &#1084;&#1080;&#1088;!"
print instr(text,"&#1077;&#1090;") ' displays 5
<<::c::
{{fbdoc item="target"}}
	- The wide-character string version of ##**Instr**## is not supported for DOS target.

{{fbdoc item="diff"}}
	- QB returns ##//start//## if ##//search//## is a zero length string.
	- QB does not support Unicode.

{{fbdoc item="see"}}
	- ##[[KeyPgInstrrev|Instrrev]]##
	- ##[[KeyPgMidfunction|Mid (Function)]]##

{{fbdoc item="back" value="CatPgString|String Functions"}}