2009-10-08 100 views
0

我有一个多行TextBox,C#,搜索字符串,ASP

txtReadDocs.Text; 

我想搜索的文本 “txtReadDocs” 的内容。

要使用简单的搜索算法:搜索用户输入的整个搜索词。例如,如果用户输入“hello”,只搜索“hello”。如果用户输入“hello world”,则仅搜索完整的术语“hello world”,而不是单个的“hello”或“world”单词/术语。 (这使得它更容易。)使搜索不区分大小写。

非常感谢你!!!!

回答

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

您可以使用扩展方法类似:

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

用法:

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