首页 热点资讯 义务教育 高等教育 出国留学 考研考公

java中如何模糊查找

发布网友

我来回答

5个回答

热心网友

你这个把四个字拆开单独找不就完了= =
所谓的模糊查找最多也就像sql里面的like
计算机本身就是精确的。你要模糊就要加入人为判断这是毋庸置疑的。

热心网友

你好,按照你的要求代码如下

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

public class text {
public static void main(String[] args) {

try {
String key = "这个字符串是将进行模糊查找的";
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("d:\\一篇文章.txt")));

StringBuffer str = new StringBuffer();
String temp;
while (null != (temp = in.readLine())) {
str.append(temp);
}

int first = str.indexOf(key);
if (first != -1) {
System.out.println("【" + key + "】在文章中的首次出现位置是:" + first);
} else {
System.out.println("【" + key + "】在文章中没有找到");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

热心网友

如果是数据库模糊查找的话,只需用like语句,
例如:
select * from emp where enp_name like “%天%”

查询用户中姓名中有“天”字的用户信息

热心网友

你是指数据库模糊查询吗?
数据库模糊查询用 like
如果是查询源码
ctrl+f

热心网友

这个只能是sql中的吧:
select * from tablename where 字段like '%条件%'

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com