开发者

C#, Search string, ASP

开发者 https://www.devze.com 2022-12-08 16:12 出处:网络
I have a MultiLine textbox, txtReadDocs.Text; I\'d like to search the contents of text \"txtReadDocs\".

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"))
{
  ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消