简体   繁体   中英

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. Does opencsv provide this functionality ?

If not, what is the best way to search in csv file.

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...
      }
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM