title: How To Use LINQ To Find Matching Data Against A List Of Strings
body: <p>I have a specialized string dictionary of (string, string) (_RulesAndTheirDescriptions) that contains the name (key) and description (value) of methods in a given class.  I currently do the following query to search for a match on the key or value and then bind that to a grid.  Works great!  </p>
  
  <pre><code>Dim Results = From v In _RulesAndTheirDescriptions _
   Where v.Value.ToString().ToUpper().Contains(Me.txtSearchFor.Text.ToUpper()) _
   Or v.Key.ToString().ToUpper().Contains(Me.txtSearchFor.Text.ToUpper()) _
   Order By v.Key _
   Select New With {.Rule = v.Key, .Description = v.Value.ToString()}
  </code></pre>
  
  <p>This works great when matching "word" or perhaps even "my word" but I would like to search for "my" and "word" and "also this".  Meaning words and phrases seperated by spaces.  Much like google and bing.  When the user enters a value I only would require that the phrases be quoted.  The following RegEx takes care of getting me a list word/phrase the user is looking for.  Now I am having a hard time combining the the above query that works with the new enhanced list.  </p>
  
  <p>Please excuse the below code.  I am just trying to test things and get it working.</p>
  
  <pre><code>Dim b As Match
  b = Regex.Match(Me.txtSearchFor.Text, "(?&lt;=(?:^|\s|,)"")[^""]*?(?="")|(?&lt;=\s|^)(?!"")[\w\W]+?(?=\s|$)")
  
  Dim sl As List(Of String) = New List(Of String)
  
  If b.Success Then
      sl.Add(b.Value.ToUpper())
  
      Dim sMatch = b.NextMatch()
  
      While sMatch IsNot Nothing AndAlso sMatch.Success
          sl.Add(sMatch.Value.ToUpper())
          sMatch = sMatch.NextMatch()
      End While
  End If
  </code></pre>
  
  <p>Per another post on this site I tried to do the following but that is not returing any results.  I suspect because the sl.ToString() returns the type and not the value?  </p>
  
  <pre><code>Dim Results = From v In _RulesAndTheirDescriptions _
   Where v.Value.ToString().ToUpper().Contains(sl.ToString()) _
   Order By v.Key _
   Select New With {.Rule = v.Key, .Description = v.Value.ToString()}
  </code></pre>
  
  <p>If I am going about this all wrong, please enlighten me.  Seems like it should be easy.  </p>
  
  <p>Thanks in advance,
  Kevin</p>