Files
mql5-skills/skills/mql5/references/docs/34-standardlibrary/1744-standardlibrary-datastructures-carraystring-carraystringsearchlinear.md
T
2026-06-23 21:47:51 +08:00

51 lines
1.0 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# SearchLinear
Searches for the element equal to the sample in the array.
```
int  SearchLinear(
   string  element      // sample
   ) const
```
Parameters
element
[in] The sample element to search in the array.
Return Value
The position of the found element - successful, -1 - the element not found.
Note
The method uses the linear search (or sequential search) algorithm for unsorted arrays.
Example:
```
//--- example for CArrayString::SearchLinear(string)
#include <Arrays\ArrayString.mqh>
//---
void OnStart()
  {
   CArrayString *array=new CArrayString;
   //---
   if(array==NULL)
     {
      printf("Object create error");
      return;
     }
   //--- add arrays elements
   //--- . . .
   //--- search element
   if(array.SearchLinear("ABC")!=-1) printf("Element found");
   else                              printf("Element not found");
   //--- delete array
   delete array;
  }
```