Kalkwst / MicroLib

MIT License
3 stars 0 forks source link

:sparkles: Text: Add WordUtils.ContainsAllWords method #13

Closed Kalkwst closed 1 year ago

Kalkwst commented 1 year ago

The ContainsAllWords method can be used to check whether a string contains all of the specified words. Here are a few examples of use cases:

  1. Searching for a specific phrase in a document: The method can be used to check whether a document contains a specific phrase by searching for all of the words in the phrase.
  2. Validating user input: The method can be used to validate user input to ensure that it contains certain keywords. For example, a form might require users to enter their name and email address, and the method could be used to ensure that the user's input contains both of these keywords.
  3. Filtering data: The method can be used to filter a collection of strings based on whether they contain certain keywords. For example, a list of product names could be filtered to only include products that contain the keywords "red" and "shirt".

The ContainsAllWords method checks if the provided string str contains all the words in the words array. It returns false if either str is null or empty, or words is null or empty. Otherwise, it checks if all the words in the words array are contained in str using a regular expression pattern that checks for whole-word matches. If all the words are found in str, it returns true, otherwise it returns false.