2009-10-08 5 views
0

J'ai une zone de texte multiligne,C#, chaîne de recherche, ASP

txtReadDocs.Text; 

Je voudrais rechercher le contenu du texte "txtReadDocs".

Pour utiliser un algorithme de recherche simple: Recherchez l'ensemble du terme de recherche entré par l'utilisateur. Par exemple, si l'utilisateur entre "Bonjour", recherchez uniquement "Bonjour". Si l'utilisateur entre "hello world", recherchez uniquement le terme complet "hello world", et non les mots/termes "hello" ou "world". (Cela le rend plus facile.) Faites votre recherche insensible à la casse.

Merci beaucoup!

Répondre

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

Vous pouvez utiliser une méthode d'extension comme ça:

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

Utilisation:

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