How can i remove specific letters from a string?

 

Hi, please someone can help me to remove letters from words in a string ?

thanks for any help

string one = "one";
double value_to_remove= -1; // this number will remove letter from words, -1, remove 1 letter

string on = " "; - QUESTION - How can i make ON string become "one" - 1 letter, = "on", removing the "e"?


void Ontick ()
{

Comment ( on);

}

 

This works similar to python's string slice, in concept not notation. 

#include <Strings\String.mqh>
class MyString : public CString
{
 public: 
   string slice(int start, int end)
   {
      if(start < 0)
         start = this.Len() + start;
      if(end < 0)
         end = this.Len()+ end;
      else if(end <= start)
         end = start;
      return this.Mid(start, end - start);
   }
   MyString *operator = (string in) { 
      this.m_string = in; 
      return &this;
   }
};



void OnStart()
{
   MyString str = "one";
   Print(str.slice(0, -1));
   // on 
   Print(str.slice(0, 2));
   // on
   
   str = "MrLuck07";
   Print(str.slice(2,-2));
   // Luck
   Print(str.slice(2, 0));
   // Luck07
   Print(str.slice(0, 2));
   // Mr
   Print(str.slice(-2, 0));
   // 07
   
   
   Print((str="MidSliceMid").slice(3,-3));
   // Slice
}
 
Perhaps you should read the manual.
Extracts a substring from a text string starting from the specified position.
          String Functions / StringSubstr - Reference on algorithmic/automated trading language for MetaTrader 5
 
whroeder1:
Perhaps you should read the manual.

I gave him the answer above...

 
thanks a lot for answer
 
Mrluck07:
thanks a lot for answer

You're welcome, now don't ever let me catch you saying OOP is useless again! ;)

 

For the sake of anyone still looking for an answer:

MQL5  use https://www.mql5.com/en/docs/strings/stringreplace

Documentation on MQL5: String Functions / StringReplace
Documentation on MQL5: String Functions / StringReplace
  • www.mql5.com
StringReplace - String Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5