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 fo开发者_StackOverflowr 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 !!!!
string searchTerm = "hello world";
bool foundIt = txtReadDocs.Text.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) >= 0;
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"))
{
...
}
精彩评论