在文本框中搜索多个单词 [英] multiple word search in textbox

查看:86
本文介绍了在文本框中搜索多个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,当我给出您拥有的步骤"时,我想搜索多个单词.它必须首先搜索所有三个单词并显示,然后再次搜索"you".并显示并拥有"按顺序搜索和显示它,            从sql server 2005的单个字段中获取

i want to search multiple words when i give for example "steps you have" it has to search all three words first and display, again it has to search "you" and display and "have" to search and display it in order,              from single field of sql server 2005

请告知对此代码的编码

推荐答案

如果您不需要查找您的步骤",步骤有和您拥有",那么以下内容可能就足够了:

If you don't need to look for "steps you", "steps have" and "you have", then the following might be sufficient:

私有常量字符串fieldName ="MyField";

公共字符串getWhereClause(字符串搜索){
  string []个单词= search.Split(new char [] {''},StringSplitOptions.RemoveEmptyEntries);
  StringBuilder WhereClause = new StringBuilder("WHERE");
 
  string fieldIs = string.Concat(,",fieldName,"='"); //使用几次

  WhereClause.Append(fieldIs).Append(search).Append('"); //首先是整个短语

  foreach(字串字词){
    WhereClause.Append("OR").Append(fieldIs).Append(word).Append('");
  }

 返回WhereClause.ToString();
}

private const string fieldName = "MyField";

public string getWhereClause(string search) {
  string[] words = search.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
  StringBuilder WhereClause = new StringBuilder("WHERE");
 
  string fieldIs = string.Concat(" ", fieldName, "='"); // is used a few times

  WhereClause.Append(fieldIs).Append(search).Append("'"); // first the entire phrase

  foreach (string word in words) {
    WhereClause.Append(" OR").Append(fieldIs).Append(word).Append("'");
  }

  return WhereClause.ToString();
}


这篇关于在文本框中搜索多个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆