StringFind

Busca una subcadena en una cadena.

int  StringFind(
   string  string_value,        // cadena en la que buscamos
   string  match_substring,     // lo que buscamos
   int     start_pos=0          // punto de partida de la búsqueda
   );

Parámetros

string_value

[in]  Cadena en la que se realiza la búsqueda.

match_substring

[in]  Subcadena buscada.

start_pos=0

[in]  Posición en la cadena desde la cual debe empezarse la búsqueda.

Valor devuelto

Devuelve el número de posición en la cadena desde la cual se empieza la subcadena buscada, o devuelve -1 si la subcadena no ha sido encontrada.

Ejemplo:

#define   RESERVE    100
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- obtenemos la divisa básica del instrumento y la divisa del beneficio
   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);
   
//--- en un ciclo a través de todos los símbolos disponibles en el servidor
   int total=SymbolsTotal(false), pos=-1;
   for(int i=0i<totali++)
     {
      //--- obtenemos el nombre del símbolo siguiente
      string name=SymbolName(ifalse);
      
      //--- buscamos en el nombre del símbolo una subcadena con el nombre de la divisa básica y
      //--- si se encuentra la subcadena, imprimimos el nombre del instrumento, su índice en la lista de divisas y el nombre de la divisa buscada en el registro
      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);
         
      //--- buscamos en el nombre del símbolo una subcadena con el nombre de la divisa básica y
      //--- si se encuentra la subcadena, imprimimos el nombre del instrumento, su índice en la lista de divisas y el nombre de la divisa buscada en el registro
      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);
     }
      
   /*
  Resultado
   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
   */
  }

Véase también

StringSubstr, StringGetCharacter, StringLen, StringLen