-2

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}}

Satish
  • 95
  • 2
  • 9
  • 6
    You have 7 questions and have not accepted a single answer to those questions. Please accept some answers in order to improve your acccept rate (which is unacceptable). – Th0rndike Jun 27 '12 at 09:01

2 Answers2

1

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;
    }
}
Hao Liu
  • 114
  • 3
  • Thanks! It could be more complex than above example.. Just wanted to know if there is any generic parser that takes both the delimiters and do the job for me. Thanks anyways! – Satish Jun 27 '12 at 22:04
0

Actually, with JSaPar you can have any character sequence for both line delimiter as well as cell delimiter. You specify which delimiter to use within your schema and it can be any number of characters.

The problem you will face by using the same character in both is that the parser will not know if you have a line break or if it is just an empty cell.

geisterfurz007
  • 3,390
  • 5
  • 29
  • 46
stenix
  • 2,661
  • 2
  • 17
  • 28