Name: Anonymous 2012-05-04 10:39
hi /prog/
I need to make a function that takes two strings, and removes all characters from the first string that are in the second string; we get marked on how efficient our code is. This is what I got so far, it's pretty shit and apparently theres a much better way to do it.
anyone want to point me in the right direction?
I need to make a function that takes two strings, and removes all characters from the first string that are in the second string; we get marked on how efficient our code is. This is what I got so far, it's pretty shit and apparently theres a much better way to do it.
#include <iostream>
#include <string.h>
void rmFromString(std::string & toBeProcessed, const std::string & toBeIgnored)
{
size_t found;
std::string newString;
found = toBeProcessed.find_first_not_of(toBeIgnored);
while (found != std::string::npos)
{
newString += toBeProcessed[found];
found = toBeProcessed.find_first_not_of(toBeIgnored, found + 1);
}
toBeProcessed = newString;
}
int main()
{
std::string toBeProcessed = "she sells sea shells on the sea shore",
toBeIgnored = "se";
rmFromString(toBeProcessed, toBeIgnored);
std::cout << toBeProcessed << std::endl;
}anyone want to point me in the right direction?