[英]Searching Using opencsv
I wanted to know, if we can search a particular row in a csv (as we do in UI using find) containing a particular word. 我想知道,是否可以在包含特定单词的csv中搜索特定行(就像我们在UI中使用find那样)。 Does opencsv provide this functionality ? opencsv是否提供此功能?
If not, what is the best way to search in csv file. 如果没有,什么是在csv文件中搜索的最佳方法。
No it doesn't but you could simply iterate through the fields 不,不是,但是您可以简单地遍历字段
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...
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.