I need to remove words from a string based on a set of words:
Words I want to remove:
DE DA DAS DO DOS AN NAS NO NOS EM E A AS O OS AO AOS P LDA AND
If I receive a string like:
EDIT: This string is already "cleaned" from any symbols
THIS IS AN AMAZING WEBSITE AND LAYOUT
The result should be:
THIS IS AMAZING WEBSITE LAYOUT
So far I have:
public static string StringWordsRemove(string stringToClean, string wordsToRemove)
{
string[] splitWords = wordsToRemove.Split(new Char[] { ' ' });
string pattern = "";
foreach (string word in splitWords)
{
pattern = @"\b" + word + "\b";
stringToClean = Regex.Replace(stringToClean, pattern, "");
}
return stringToClean;
}
But it's not removing the words, any idea?
I don't know if I'm using the most eficient way to do it, maybe put the words in a array just to avoid spliting them all the time?
Thanks