Answers for "how to delete elements from a string"

12

erasing a character from a string in c++

// string::erase
#include <iostream>
#include <string>

int main ()
{
  std::string str ("This is an example sentence.");
  std::cout << str << 'n';
                                           // "This is an example sentence."
  str.erase (10,8);                        //            ^^^^^^^^
  std::cout << str << 'n';
                                           // "This is an sentence."
  str.erase (str.begin()+9);               //           ^
  std::cout << str << 'n';
                                           // "This is a sentence."
  str.erase (str.begin()+5, str.end()-9);  //       ^^^^^
  std::cout << str << 'n';
                                           // "This sentence."
  return 0;
}
Posted by: Guest on May-13-2020
19

remove from string python

"Str*ing With Chars I! don't want".replace('!','').replace('*','')
Posted by: Guest on May-13-2020

Code answers related to "how to delete elements from a string"

Python Answers by Framework

Browse Popular Code Answers by Language