AutoIt StringInStr Function

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

3659 views

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.

Parameters

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.
Optional
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.
Optional

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)
EndIf

Tell us what you think:

  1. How to declare and work with variables in AutoIt, as well as some background information.
  2. Everything you need to know about working with minimized windows.
  3. How to set the request headers when performing HTTP requests.
  4. This Tutorial will focus on post requests in AutoIt, using the Winhttprequest.5.1 object.
  5. How to use while, for, and do until loops, and how to loop through arrays and object in AutoIt.

More in: AutoIt Tutorials