0

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.

Amol Sharma
  • 1,521
  • 7
  • 20
  • 40

1 Answers1

3

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...
      }
   }
}
Reimeus
  • 158,255
  • 15
  • 216
  • 276