I am parsing a csv file with Apache Commons CSVRecord and CSVFormat in Java I got the following record in String format Records : CSVRecord [comment=null, mapping={Id=0, FirstName=1, LastName=2}, recordNumber=1, values=[1, John, Wayne]]
I need to extract the values only For ex: 1, John, Wayne
Used the following options to get the result.
String[] split = record.split("values=\\[");
String result = split[1].substring(0, split[1].length() - 2);
My Question is: Is there a better option(Faster) than this in Java?
Try this:
String txt = "CSVRecord [comment=null, mapping={Id=0, FirstName=1, LastName=2}, recordNumber=1, values=[1, John, Wayne]]";
String[] sub = txt.substring(txt.indexOf("values=[")).split("[\\[\\]]");
System.out.println(sub[1]);
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.