Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Linq to filter out certain Keys from a Dictionary and return a new dictionary2
    text
    copied!<p>Related to this question: <a href="https://stackoverflow.com/questions/10907344/using-linq-to-filter-out-certain-keys-from-a-dictionary-and-return-a-new-diction">Using Linq to filter out certain Keys from a Dictionary and return a new dictionary</a></p> <p>I got a control for a auto-complete that uses dictionary. Scenario was every word in my RichTextBox (to serve as code-editor) will automatically add in my list of autocomplete. Like if I type the word "asdasdasd" in RichTextBox , the word "asdasdasd" will automatically be added in my auto-complete .</p> <p>using this code:</p> <pre><code>private IEnumerable&lt;AutocompleteItem&gt; BuildList() { //find all words of the text var words = new Dictionary&lt;string, string&gt;(); var keysToBeFiltered = new HashSet&lt;string&gt; { "Do", "Not" }; var filter = words.Where(p =&gt; !keysToBeFiltered.Contains(p.Key)) .ToDictionary(p =&gt; p.Key, p =&gt; p.Value); foreach (Match m in Regex.Matches(rtb_JS.Text, @"\b\w+\b")) filter[m.Value] = m.Value; //foreach (Match m in Regex.Matches(rtb_JS.Text, @"^(\w+)([=&lt;&gt;!:]+)(\w+)$")) //filter[m.Value] = m.Value; foreach (var word in filter.Keys) { yield return new AutocompleteItem(word); } } </code></pre> <p>Now the word "Do" and "Not" are still included to auto-complete using the code above. Also when my form loads, a specific default script appears that must be there all the time. So i can't change it.</p> <p>Two possible solutions I have do to fix this: 1. don't allow those default words used in default script add in my autocomplete when form loads.(make list of words that prevent from adding into my list) 2. detect the line that has commented "//" or "/*" and prevent words from it to add in my dictionary.</p> <p>Hope you can help me. Please tell me if I need to revise my question and I'll revise/update it ASAP.</p> <p>main_Q:</p> <p>how to prevent adding commented words from richtextbox (line that starts with // or /*) into autocomplete</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload