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_base, symbol_currency_profit);
   
//--- в цикле по всем имеющимся на сервере символам
   int total=SymbolsTotal(false), pos=-1;
   for(int i=0; i<total; i++)
     {
      //--- получаем имя очередного символа
      string name=SymbolName(i, false);
      
      //--- ищем в имени символа подстроку с наименованием базовой валюты и
      //--- если подстрока найдена - выведем в журнал наименование инструмента, его индекс в списке валют и имя искомой валюты
      pos = StringFind(name, symbol_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", name, i, symbol_currency_base, pos);
         
      //--- ищем в имени символа подстроку с наименованием котируемой валюты и
      //--- если подстрока найдена - выведем в журнал наименование инструмента, его индекс в списке валют и имя искомой валюты
      pos = StringFind(name, symbol_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", name, i, symbol_currency_profit, pos);
     }
      
   /*
   Результат
   StringFind (EURUSD,D1)   Symbol Currency Base: EUR
   StringFind (EURUSD,D1)   Symbol Currency Profit: USD
   The 'EURUSD' symbol at index 0 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURUSD' symbol at index 0 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'GBPUSD' symbol at index 1 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'USDCHF' symbol at index 2 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDJPY' symbol at index 3 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDCNH' symbol at index 4 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDRUB' symbol at index 5 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'AUDUSD' symbol at index 6 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'NZDUSD' symbol at index 7 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'USDCAD' symbol at index 8 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDSEK' symbol at index 9 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDHKD' symbol at index 10 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDSGD' symbol at index 11 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDNOK' symbol at index 12 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDDKK' symbol at index 13 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDTRY' symbol at index 14 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDZAR' symbol at index 15 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDCZK' symbol at index 16 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDHUF' symbol at index 17 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDPLN' symbol at index 18 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDRUR' symbol at index 19 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'EURAUD' symbol at index 27 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURCAD' symbol at index 28 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURCHF' symbol at index 29 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURCZK' symbol at index 30 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURDKK' symbol at index 31 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURGBP' symbol at index 32 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURHKD' symbol at index 33 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURHUF' symbol at index 34 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURJPY' symbol at index 35 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURNOK' symbol at index 36 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURNZD' symbol at index 37 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURPLN' symbol at index 38 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURRUR' symbol at index 39 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURRUB' symbol at index 40 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURSEK' symbol at index 41 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURTRY' symbol at index 42 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURZAR' symbol at index 43 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'XAUUSD' symbol at index 47 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'XAUEUR' symbol at index 48 in the list contains the 'EUR' currency. Substring position in the symbol name: 3
   The 'XAGUSD' symbol at index 50 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'XAGEUR' symbol at index 51 in the list contains the 'EUR' currency. Substring position in the symbol name: 3
   The 'USDCRE' symbol at index 53 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'XPDUSD' symbol at index 65 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'XPTUSD' symbol at index 66 in the list contains the 'USD' currency. Substring position in the symbol name: 3
   The 'USDGEL' symbol at index 67 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDMXN' symbol at index 68 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'EURMXN' symbol at index 69 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'USDCOP' symbol at index 75 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDARS' symbol at index 76 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDCLP' symbol at index 77 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'EURSGD' symbol at index 89 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'USDILS' symbol at index 95 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDTHB' symbol at index 122 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'USDRMB' symbol at index 123 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   The 'EURILS' symbol at index 126 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'EURCNH' symbol at index 137 in the list contains the 'EUR' currency. Substring position in the symbol name: 0
   The 'USDBRL' symbol at index 139 in the list contains the 'USD' currency. Substring position in the symbol name: 0
   */
  }

Смотри также

StringSubstr, StringGetCharacter, StringLen, StringLen