StringFind

Поиск подстроки в строке.

int  StringFind(
   string  string_value,        // строка, в которой ищем
   string  match_substring,     // что ищем
   int     start_pos=0          // с какой позиции начинать поиск
   );

Параметры

string_value

[in]  Строка, в которой производится поиск.

match_substring

[in]  Искомая подстрока.

start_pos=0

[in]  Позиция в строке, с которой должен быть начат поиск.

Возвращаемое значение

Возвращает номер позиции в строке, с которой начинается искомая подстрока, либо -1, если подстрока не найдена.

Пример:

#define   RESERVE    100
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- получим базовую валюту инструмента и валюту прибыли
   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);
   
//--- в цикле по всем имеющимся на сервере символам
   int total=SymbolsTotal(false), pos=-1;
   for(int i=0i<totali++)
     {
      //--- получаем имя очередного символа
      string name=SymbolName(ifalse);
      
      //--- ищем в имени символа подстроку с наименованием базовой валюты и
      //--- если подстрока найдена - выведем в журнал наименование инструмента, его индекс в списке валют и имя искомой валюты
      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);
         
      //--- ищем в имени символа подстроку с наименованием котируемой валюты и
      //--- если подстрока найдена - выведем в журнал наименование инструмента, его индекс в списке валют и имя искомой валюты
      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);
     }
      
   /*
   Результат
   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
   */
  }

Смотри также

StringSubstr, StringGetCharacter, StringLen, StringLen