My stringsubstr is not working as expected

 

I am getting data out of a file, in this case, the value I am getting is "EUR/USD". Then I perform a little string manipulation to get the "/" out of the string.

   int Handle;
   string FileName = "Callouts1.csv";
   string Symb = "";
   string TmpSymb = "";
   double Entry;
   double StopL;
   double FirstNum;
   double SecondNum;
   
   Handle=FileOpen(FileName,FILE_CSV|FILE_READ,",");    // File opening
   if(Handle<1)                                         // File opening fails
   {
      if(GetLastError()==4103)                          // If the file does not exist,..
      {
         Alert("No file named ",FileName);              //.. inform trader
      }
      else
      {
                                                         // If any other error occurs..
         Alert("Error while opening file ",FileName);    //..this message
         PlaySound("Bzrrr.wav");                         // Sound accompaniment
         return;                                         // Exit start()
      }
   }
   
   while(FileIsEnding(Handle)==false)                    // While the file pointer..     
   {                                                     // ..is not at the end of the file
      OP_Type = FileReadString(Handle);                  // Is this a buy or sell
      Symb = FileReadString(Handle);                     // What symbol?
      Entry = FileReadNumber(Handle);                    // Entry price
      StopL = FileReadNumber(Handle);                    // Stop price
      FirstNum = FileReadNumber(Handle);                 // First price
      SecondNum = FileReadNumber(Handle);                   // Second price
      TmpSymb = StringSubstr(Symb,0,3);
      TmpSymb = StringConcatenate(TmpSymb,StringSubstr(Symb,4,7));
      Print("Symb:", Symb, "TmpSymb:", TmpSymb);
      if (StringSubstr(Symbol(),0,6) == TmpSymb)
      {
         Print("We have: ", Symbol());
         if (OP_Type == "Buy")
         {
            Print("getting ", OP_Type);
            BuyEntry = Entry;
            BuyFirst = FirstNum;
            BuySecond = SecondNum;
            BuyStopLoss = StopL;
            Print(Symbol(), " has a ", OP_Type, " with Entry: ", BuyEntry, " First: ", BuyFirst, " Second: ", BuySecond, " and stop: ", BuyStopLoss);
         }
         else
         {
            Print("getting ", OP_Type);
            SellEntry = Entry;
            SellFirst = FirstNum;
            SellSecond = SecondNum;
            SellStopLoss = StopL;
            Print(Symbol(), " has a ", OP_Type, " with Entry: ", SellEntry, " First: ", SellFirst, " Second: ", SellSecond, " and stop: ", SellStopLoss);
         }
      }
      else
      {
         Print("We did not get ", TmpSymb, " in ", Symbol());
      }
   }
   
   FileClose( Handle );                // Close file

Notice the follow:

      TmpSymb = StringSubstr(Symb,0,3);
      TmpSymb = StringConcatenate(TmpSymb,StringSubstr(Symb,4,7));
      Print("Symb:", Symb, "TmpSymb:", TmpSymb);

This works with the result of:

2009.07.21 09:30:49 Callout1 EURUSDgfx,M1: Symb:Eur/UsdTmpSymb:EurUsd

The next part is an if condition to get the stringsubstr of TmpSymb, if it was found, it would add the values to the vars, in this case, it fails to find...

      if (StringSubstr(Symbol(),0,6) == TmpSymb)
      {
         Print("We have: ", Symbol());
         if (OP_Type == "Buy")
         {
            Print("getting ", OP_Type);
            BuyEntry = Entry;
            BuyFirst = FirstNum;
            BuySecond = SecondNum;
            BuyStopLoss = StopL;
            Print(Symbol(), " has a ", OP_Type, " with Entry: ", BuyEntry, " First: ", BuyFirst, " Second: ", BuySecond, " and stop: ", BuyStopLoss);
         }
         else
         {
            Print("getting ", OP_Type);
            SellEntry = Entry;
            SellFirst = FirstNum;
            SellSecond = SecondNum;
            SellStopLoss = StopL;
            Print(Symbol(), " has a ", OP_Type, " with Entry: ", SellEntry, " First: ", SellFirst, " Second: ", SellSecond, " and stop: ", SellStopLoss);
         }
      }
      else
      {
         Print("We did not get ", TmpSymb, " in ", Symbol());
      }

Result:

2009.07.21 09:30:49 Callout1 EURUSDgfx,M1: We did not get EurUsd in EURUSDgfx

 

The reason is that the arithmetic comparison == correctly identifies that the upper and lower case letters are different ascii characters.


You have 2 options:

1) Use the StringCompare() function which ignores case

or

2) Convert the strings to a common case using StringUpperCase() or StringLowerCase() prior to comparison


CB

 
Offtop, why do you use 4,7? I guess you need use 4,3, because you need the length, not from position to position.
 
cloudbreaker wrote >>

The reason is that the arithmetic comparison == correctly identifies that the upper and lower case letters are different ascii characters.

You have 2 options:

1) Use the StringCompare() function which ignores case

or

2) Convert the strings to a common case using StringUpperCase() or StringLowerCase() prior to comparison

CB

Thanks Cloud, I could not find these functions, that is what I need.

 
Roger wrote >>
Offtop, why do you use 4,7? I guess you need use 4,3, because you need the length, not from position to position.

True 4,3 would probably be more efficient

 
LEHayes wrote >>

Thanks Cloud, I could not find these functions, that is what I need.

'Strings: Table of ASCII Symbols and Its Use'

Reason: