Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Random question

Name: Anonymous 2009-11-25 21:52

Using c++, I have a string vector containing thousands of elements. I know I can erase a specific element using:

vectorName.erase(remove(vectorName.begin(),vectorName.end(),"whatever"),vectorName.end());

In that example it would get rid of any vector elements that equaled "whatever".

I'm looking to erase certain elements if anywhere in that element it has a certain combination of letters. In my case, I want to erase any URLs that make it into the vector, so I would erase any element that contained "http" or "www" in it.

I tried googling this, but I have no clue what to look for. Can anyone offer their expertise? Is there a one line solution using vectorName.erase()?

Name: Anonymous 2009-11-25 22:09

>>1
vectorName = [s for s in vectorName where "http" not in s and "www" not in s]

Oh wait, sepples...

for (std::vector<std::string>::iterator i = vectorName.begin(); i != vectorName.end(); ++i)
  if (i->find("http") != -1 || i->find("www") != -1)
    vectorName.erase(i--);

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List