StringFind

Search for a substring in a string.

int  StringFind(
   string  string_value,        // string in which search is made
   string  match_substring,     // what is searched
   int     start_pos=0          // from what position search starts
   );

Parameters

string_value

[in]  String, in which search is made.

match_substring

[in]  Searched substring.

start_pos=0

[in]  Position in the string from which search is started.

Return Value

Returns position number in a string, from which the searched substring starts, or -1, if the substring is not found.

Example:

#define   RESERVE    100
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- get the symbol base currency and the profit currency
   string symbol_currency_base  =SymbolInfoString(Symbol(), SYMBOL_CURRENCY_BASE);
   string symbol_currency_profit=SymbolInfoString(Symbol(), SYMBOL_CURRENCY_PROFIT);
   PrintFormat("Symbol Currency Base: %s\nSymbol Currency Profit: %s"symbol_currency_basesymbol_currency_profit);
   
//--- in the loop through all symbols available on the server
   int total=SymbolsTotal(false), pos=-1;
   for(int i=0i<totali++)
     {
      //--- get the name of the next symbol
      string name=SymbolName(ifalse);
      
      //--- look for a substring in the symbol name with the name of the base currency and
      //--- if a substring is found, display the symbol name, its index in the currency list and the name of the searched currency in the log
      pos = StringFind(namesymbol_currency_base);
      if(pos >= 0)
         PrintFormat("The '%s' symbol at index %u in the list contains the '%s' currency. Substring position in the symbol name: %d"nameisymbol_currency_basepos);
         
      //--- look for a substring in the symbol name with the name of the quoted currency and
      //--- if a substring is found, display the symbol name, its index in the currency list and the name of the searched currency in the log
      pos = StringFind(namesymbol_currency_profit);
      if(pos >= 0)
         PrintFormat("The '%s' symbol at index %u in the list contains the '%s' currency. Substring position in the symbol name: %d"nameisymbol_currency_profitpos);
     }
      
   /*
   Result
   StringFind (EURUSD,D1)   Symbol Currency BaseEUR
   StringFind (EURUSD,D1)   Symbol Currency ProfitUSD
   The 'EURUSDsymbol at index 0 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURUSDsymbol at index 0 in the list contains the 'USDcurrencySubstring position in the symbol name3
   The 'GBPUSDsymbol at index 1 in the list contains the 'USDcurrencySubstring position in the symbol name3
   The 'USDCHFsymbol at index 2 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDJPYsymbol at index 3 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDCNHsymbol at index 4 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDRUBsymbol at index 5 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'AUDUSDsymbol at index 6 in the list contains the 'USDcurrencySubstring position in the symbol name3
   The 'NZDUSDsymbol at index 7 in the list contains the 'USDcurrencySubstring position in the symbol name3
   The 'USDCADsymbol at index 8 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDSEKsymbol at index 9 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDHKDsymbol at index 10 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDSGDsymbol at index 11 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDNOKsymbol at index 12 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDDKKsymbol at index 13 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDTRYsymbol at index 14 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDZARsymbol at index 15 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDCZKsymbol at index 16 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDHUFsymbol at index 17 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDPLNsymbol at index 18 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDRURsymbol at index 19 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'EURAUDsymbol at index 27 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURCADsymbol at index 28 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURCHFsymbol at index 29 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURCZKsymbol at index 30 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURDKKsymbol at index 31 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURGBPsymbol at index 32 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURHKDsymbol at index 33 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURHUFsymbol at index 34 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURJPYsymbol at index 35 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURNOKsymbol at index 36 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURNZDsymbol at index 37 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURPLNsymbol at index 38 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURRURsymbol at index 39 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURRUBsymbol at index 40 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURSEKsymbol at index 41 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURTRYsymbol at index 42 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURZARsymbol at index 43 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'XAUUSDsymbol at index 47 in the list contains the 'USDcurrencySubstring position in the symbol name3
   The 'XAUEURsymbol at index 48 in the list contains the 'EURcurrencySubstring position in the symbol name3
   The 'XAGUSDsymbol at index 50 in the list contains the 'USDcurrencySubstring position in the symbol name3
   The 'XAGEURsymbol at index 51 in the list contains the 'EURcurrencySubstring position in the symbol name3
   The 'USDCREsymbol at index 53 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'XPDUSDsymbol at index 65 in the list contains the 'USDcurrencySubstring position in the symbol name3
   The 'XPTUSDsymbol at index 66 in the list contains the 'USDcurrencySubstring position in the symbol name3
   The 'USDGELsymbol at index 67 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDMXNsymbol at index 68 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'EURMXNsymbol at index 69 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'USDCOPsymbol at index 75 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDARSsymbol at index 76 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDCLPsymbol at index 77 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'EURSGDsymbol at index 89 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'USDILSsymbol at index 95 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDTHBsymbol at index 122 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'USDRMBsymbol at index 123 in the list contains the 'USDcurrencySubstring position in the symbol name0
   The 'EURILSsymbol at index 126 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'EURCNHsymbol at index 137 in the list contains the 'EURcurrencySubstring position in the symbol name0
   The 'USDBRLsymbol at index 139 in the list contains the 'USDcurrencySubstring position in the symbol name0
   */
  }

See also

StringSubstr, StringGetCharacter, StringLen, StringLen