gpt4 book ai didi

java - 使用 opencsv 搜索

转载 作者:行者123 更新时间:2023-12-01 23:46:48 26 4
gpt4 key购买 nike

我想知道,我们是否可以在 csv 中搜索包含特定单词的特定行(就像我们在 UI 中使用 find 所做的那样)。 opencsv提供这个功能吗?

如果没有,在 csv 文件中搜索的最佳方法是什么。

最佳答案

不,它没有,但您可以简单地迭代字段

CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
String [] nextLine;
String searchWord = ".*\\d+.*"; // field contains integer?
while ((nextLine = reader.readNext()) != null) {
for (String field: nextLine) {
if (field.matches(searchWord)) {
// matched word...
}
}
}

关于java - 使用 opencsv 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16918195/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com