Remove Spaces from .TxT files Script/Function ?

 

Does anyone have a function or script which removes excess spaces (2 or more spaces) from text.txt files? 

The StringTrim commands are not working for me.

 

I assume you mean a runtime script for use in trading (otherwise you could just use Word or any other text editor and just do a replace a double space with a single space).

Typically what you would do in C is just to read the string one character at a time and if the character is not a space pass it on to the new string. This is the sort of function that new programmers start out writing. It would be a good exercise for you to write one as it will improve you programming skill.

 
Thank you dabbler but I'm looking for something more automated using mql4. Oh, and I've been trying to do that using mql4 but the other way around. I read the whole entire file into one variable and tried to use StringTrimLeft and StringTrimRight to manipulate it. Then I tried to read one character at a time using the FileRead(Handle,1) but it seems like it read an entire line until it hits line-break. I also wanna get rid of the line_breaks and Tabs if any exists. I tried to use their uni-code character to find and replace them with StringSetChar but with no luck.
 

please try this

//+------------------------------------------------------------------+
//| Function..: StringTransform                                      |
//| Purpose...: Transform a matched string in text with a new string.|
//| Example...: StringTransform("oNe mAn"," ",""); // oNemAn         |
//+------------------------------------------------------------------+
string StringTransform(string sText, string sFind=" ", string sReplace="") {
  int    iLenText=StringLen(sText), iLenFind=StringLen(sFind), i;
  string sReturn="";
  
  for(i=0; i<iLenText; i++) {
    if(StringSubstr(sText,i,iLenFind)==sFind) {
      sReturn=sReturn+sReplace;
      i=i+iLenFind-1;
    }
    else sReturn=sReturn+StringSubstr(sText,i,1);
  }
  return(sReturn);
}
 
sxTed:

please try this

Cool, thanks I'll try it. 

Update: It worked like a Charm. :) many thanks  sxTed.

 
Edward Hirsch #:

please try this

Perfect, Thanks as well!