Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use a simple LINQ query, if all you need is to check for substrings:</p> <pre><code>var q = words.Any(w =&gt; myText.Contains(w)); // returns true if myText == "This password1 is weak"; </code></pre> <p>If you want to check for whole words, you can use a regular expression:</p> <ol> <li><p>Matching against a regular expression that is the disjunction of all the words:</p> <pre><code>// you may need to call ToArray if you're not on .NET 4 var escapedWords = words.Select(w =&gt; @"\b" + Regex.Escape(w) + @"\b"); // the following line builds a regex similar to: (word1)|(word2)|(word3) var pattern = new Regex("(" + string.Join(")|(", escapedWords) + ")"); var q = pattern.IsMatch(myText); </code></pre></li> <li><p>Splitting the string into words with a regular expression, and testing for membership on the words collection (this will get faster if you use make words into a <code>HashSet</code> instead of a <code>List</code>):</p> <pre><code>var pattern = new Regex(@"\W"); var q = pattern.Split(myText).Any(w =&gt; words.Contains(w)); </code></pre></li> </ol> <p>In order to filter a collection of sentences according to this criterion all you have to do is put it into a function and call <code>Where</code>:</p> <pre><code> // Given: // bool HasThoseWords(string sentence) { blah } var q = sentences.Where(HasThoseWords); </code></pre> <p>Or put it in a lambda:</p> <pre><code> var q = sentences.Where(s =&gt; Regex.Split(myText, @"\W").Any(w =&gt; words.Contains(w))); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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