How to boil a list down to least common strings?
<p>I have a <code>HashSet&lt;string&gt;</code> which I'm loading vulgar words into for filtering purposes.  The problem is that my list will contain "Fu" and also the word spelled out completely.  What I want to do is filter the list down so it only contains "Fu", which would eliminate any other forms of the word from the list.  </p>

<p>In other words, I want to remove all strings in the list where its substring is also a list item.</p>

<p>How should I go about doing this?</p>

<p>I have the following where <code>excludedWords</code> is the original <code>HashSet</code>, but it's not working completely:</p>

<pre><code>HashSet&lt;string&gt; copy = new HashSet&lt;string&gt;(exludedWords);

foreach (string w in copy)
{
    foreach (string s in copy)
    {
        if (w.Contains(s) &amp;&amp; w.Length &gt; s.Length)
        {
            result.Remove(w);
        }
    }
}
</code></pre>
