How can i remove specific letters from a string?

To add comments, please log in or register
Mrluck07
426
Mrluck07  

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);

}

nicholi shen
1885
nicholi shen  

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
}
whroeder1
17943
whroeder1  
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
nicholi shen
1885
nicholi shen  
whroeder1:
Perhaps you should read the manual.

I gave him the answer above...

Mrluck07
426
Mrluck07  
thanks a lot for answer
nicholi shen
1885
nicholi shen  
Mrluck07:
thanks a lot for answer

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

To add comments, please log in or register