views:

69

answers:

2

Hello,

I have a MultiLine textbox,

txtReadDocs.Text;

I'd like to search the contents of text "txtReadDocs".

To use a simple search algorithm: Search for the entire search term entered by the user. For example, if the user enters "hello", search only for "hello". If the user enters "hello world", search only for the complete term "hello world", and not the individual "hello" or "world" words/terms. (This makes it easier.) Make your search case-insensitive.

Thank You so much !!!!

+3  A: 
string searchTerm = "hello world";
bool foundIt = txtReadDocs.Text.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) >= 0;
Jonas
+1  A: 

You can use an extension method like that:

public static bool ContainsCI(this string target, string searchTerm)
{
  int results = target.IndexOf(searchTerm, StringComparison.CurrentCultureIgnoreCase);
  return results == -1 ? false : true;
}

Usage:

if (txtReadDocs.Text.ContainsCI("hello world"))
{
  ...
}
JRoppert