javaparsingtext-parsingparser-generatoropencsv

Java simple line parser


I could see bunch of java parsers like OpenCSV, antlr, jsapar etc, but I dont see any of those with ability to specify both custom line seperator and column seperator? Do we have any such easy to use libraries. I dont want to write one using Scanner or Stringtokenizer now!

Eg. A | B || C | D || E | F

want to break this above string to something like {{A,B},{C,D},{E,F}}


Solution

  • You can parse it yourself, it's quite simple to achieve. I haven't test this code practically, you may try it yourself.

    line_delimiter = "||";
    column_delimiter = "|";
    
    String rows[];
    rows = str.split(line_delimiter);
    for (int i = 0; i < rows.length; i++) {
        String columns[];
        columns = rows[i].split(column_delimiter);
        for (int j = 0; j < columns.length; j++) {
            // Do something to your data here;
        }
    }