select text from abc where %'aaa'%;用匹配符号不就可以了吗?!

解决方案 »

  1.   

    通常来说,用这是数据库的问题。
    在SQL Server中,如果对某一张表的某个文本字段做了全文索引就可以实现。
    比如,对Books表的BookName(nvarchar(100))、Comments(ntext)字段设置了全文索引,那么用类似:
    select * from Books where contains(Comments, "优秀")
    的SQL就可以找到符合条件的记录。
    contains只是其中之一,还有其它函数。买一本SQL Server的书,都会讲到。
      

  2.   

    如果要进行查询关键字加亮的话,有专门的函数:
    php:str_replace,其他的编程语言类似!
      

  3.   

    程序中输出数据之前替换掉关键字嘛
    用<font color=red>关键字</font>替换关键字不就行了
      

  4.   

    感谢各位!
    不过我最终的结果是要将这篇文章在网页上输出,如何在输出之前将其中的关键字<font color=red>关键字</font>插进去呢?
    烦请各位指教!
      

  5.   

    先定义replace:
      private String replace(String news, String old, String newstr) {    StringBuffer sb = new StringBuffer();    int pos = 0;
        int last = 0;
        pos = news.indexOf(old, last);
        while ( pos > 0 ) {      sb.append(news.substring(last, pos));
          sb.append(newstr);      last = pos + old.length();      pos = news.indexOf(old, last);
        }    sb.append((news.substring(last, news.length())));    return sb.toString();
      }然后:
    text = "文章内容.......";   
    result = replace(text,"关键字", "<font color=red>关键字</font>");
      

  6.   

    上法无法检索第一个字符,应该为:
    private String replace(String news, String old, String newstr) {StringBuffer sb = new StringBuffer();int pos = 0;
    int last = 0;
    pos = news.indexOf(old, last);
    if (pos==0)
    {sb.append(newstr);
    last = pos + old.length();
    pos = news.indexOf(old, last);
    }
    while ( pos > 0 ) {sb.append(news.substring(last, pos));
    sb.append(newstr);last = pos + old.length();pos = news.indexOf(old, last);
    }sb.append(news.substring(last, news.length()));return sb.toString();
    }