megabyte214
Programmer
I am using StringTokenizer to parse a text file. The file contains items with different attributes, delimitated by commas.
An example line is:
0001,"Abbot, Baker, and Miller”,4444,"fiction",,06182000
I have 2 questions. First, using StringTokenizer, is there a way to differentiate between a comma in an attribute and a comma between attributes?
Secondly, StringTokenizer doesn’t seem to like it when there are 2 commas together. This happens when an attribute is blank. If I put a space between the commas, it is fine, but unfortunately, I cannot change the file.
I realize that I can write my own parser to do all of this, but I am trying to take advantage of an existing class if there is one that can help me.
Would StreamTokenizer be better for what I am trying to do? I have never used it before.
Thanks in advance.
An example line is:
0001,"Abbot, Baker, and Miller”,4444,"fiction",,06182000
I have 2 questions. First, using StringTokenizer, is there a way to differentiate between a comma in an attribute and a comma between attributes?
Secondly, StringTokenizer doesn’t seem to like it when there are 2 commas together. This happens when an attribute is blank. If I put a space between the commas, it is fine, but unfortunately, I cannot change the file.
I realize that I can write my own parser to do all of this, but I am trying to take advantage of an existing class if there is one that can help me.
Would StreamTokenizer be better for what I am trying to do? I have never used it before.
Thanks in advance.