-1

Is there any way to trim everything after a given character, let's say '_' . Is there any way to do that? Example:

string ul = "The quick brown fox jumped over the lazy dog________ dog dog"
int ullocation = ul.find("_")
(code to remove everything after the underline using the int)
flying
  • 1
  • 3

1 Answers1

2

Use std::string::find() and std:string::erase(), eg:

string ul = "The quick brown fox jumped over the lazy dog________ dog dog";
string::size_type idx = ul.find("_");
if (idx != string::npos) ul.erase(idx);

Live Demo

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770