2009-10-08 98 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")) 
{ 
    ... 
}