public class CSVParser {
public static final String CSV_REGEX_PATTERN = "\"([^\"]+?)\",?([^,]+),?,";
public static final String TSV_REGEX_PATTERN = "\t{1}";
public static Pattern csvRE;
public static Pattern tsvRE;
static {
csvRE = Pattern.compile(CSV_REGEX_PATTERN);
tsvRE = Pattern.compile(TSV_REGEX_PATTERN);
}
private List parse(String line) {
List list = new ArrayList();
Matcher m = csvRE.matcher(line);
// For each field
while (m.find()) {
String match = m.group();
if (match == null)
break;
//this will remove trailing , - comment this out if we dont want that affect
if (match.endsWith(",")) {
match = match.substring(0, match.length() - 1);
}
if (match.startsWith("\"")) {
match = match.substring(1, match.length () - 1);
}
if (match.length() == 0)
match = null;
list.add(match);
}
return list;
}
}
The Motorcycle Diaries
-
The journey of a man which changed his life forever! What more one could
write about this movie with the preceding line aptly describing the movie?
I fe...
No comments:
Post a Comment