Share via:

AutoIt StringInStr Function

The StringInStr function can be used to find a string in another string.


Edited: 2017-03-25 03:07

The AutoIt StringInStr is used to check for the existence of one string, inside another string. An example could be, checking if a given word or phrase exists, in a document or file.


stringThe source to be checked.Required
substringThe string to search for.Required
casesenseControls the case sensitivity of the search.
  • $STR_NOCASESENSE (0) – The search is case-insensitive (including both upper and lowercase letters).
  • $STR_CASESENSE (1) – The search is case-sensitive.
  • $STR_NOCASESENSEBASIC (2) – The search is case-insensitive, and using basic/faster comparison.
occurrenceControls which occurrence in the string to find. Use a negative value to search from the right. Default is 1.Optional
startThe start position of the search.Optional
countThe maximum number of characters to search for.
  • This should not be lower than the substring.
  • You can combine this with the start parameter, to limit the search to a substring of the source.

AutoIt StringInStr example

In the below example, the $Source variable is checked for the $StringToCheckFor variable.

The $Source contains the loaded data, and the $StringToCheckFor is whatever is to be checked for, such as a word or phrase.

$Source = 'The poo is in the toilet.';
$StringToCheckFor = 'poo';
$result = StringInStr($Source, $StringToCheckFor)
If $result > 1 Then
  MsgBox(0, $StringToCheckFor & " Found", $Source)