如何在CSV表中查找字符串的最后使用并在该行上找到另一列的值
使用 Java 处理,我试图找到最后一次在表列中找到特定字符串值的时间,并从其旁边的单元格中获取另一个值。 我该怎么做这样的事情?
Using Java Processing I'm trying to find the last time that a specific string value is found in a table column and get another value from the cell next to it.
How would I do something like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用任何可用的 CSV 解析工具来读取您的文件。例如,Apache Commons CSV。
当您阅读每一行时,测试它是否包含您的目标值。如果是这样,请通过存储在变量中来记住该行。每次找到命中时,将先前隐藏的值替换为最新值,并存储在同一变量中。
读取文件后,符合您条件的最后一行位于该变量中。现在读取该行的相邻单元格。瞧,你的结果。
您会在现有的问答中找到许多读取 CSV 文件的示例。再次,我建议您使用库来读取和解析 CSV,而不是自己执行这项工作。
Use any of the several available CSV parsing tools to read your file. For example, Apache Commons CSV.
As you read in each line, test if it contains your target value. If so, remember that row by stashing in a variable. Each time you find a hit, replace the previously stashed value with the latest, storing in that same variable.
When done reading the file, the last row meeting your criteria is in that variable. Now read the adjacent cell from that row. Voilà, your result.
You will find many examples of reading CSV files in existing Questions and Answers. Again, I recommend you use a library for reading and parsing the CSV rather than perform that chore yourself.