Search code examples
mql4mql5

How to Remove a certain part of a string (if exists)?


I am trying to make the EA look for a certain value in a string and if that value exists in the string then remove it.

I tried doing it using the StringReplace() but i noticed it only returns the number of replacements and didnt actually returned the updated string:

string v5="- .82523";
          string temp2 =  v5;
          temp2= StringReplace(temp2," ","");
          Print(v5,temp2);

in the above code there is a white space between "-" and ".82523" and i am trying to remove that white space.

so the string is - .82523 and i am trying to get -.82523 , which function can be used for this ?

initially i thought i could do it by using the StringReplace() function , but seems like it only returns the Number of replacements that had happened and not the updated string.

Thanks in Advance


Solution

  • You are using the StringReplace() function incorrectly. Try the following code (from your example).

       string v5="- .82523";
       string temp2 =  v5;
       StringReplace(temp2," ","");
       Print("<",v5,"> <",temp2,">");