Hi All,
I was wondering if someone could help me with this problem I have. Here is the scenario:
I have developed a Java application which allows users to upload two file types .xls and .csv. The files contain raw data. In a .csv a comma delimeter is used to determine the end of one field and the beginning of another. So for example:
12.78, sometxt,,, "123 street, city, state, zip", 13.45, "lastname, firstname",,,"company name, inc.",,
This csv file has to be converted to a tilde delimited file for another application so the result should be:
12.78~ sometxt~~~ "123 street, city, state, zip"~ 13.45~ "lastname, firstname"~~~"company name, inc."~~
The application has to verify that all the fields exist in the file, and it does this by counting the comma separators. If the criteria is not met, the file is rejected. For example if 10 fields are expected then 10 commas should be present.
Now heres the bit I'm having trouble with. When I'm doing the count for commas, how do I ignore the commas between the quotes? Also, how do I ignore the commas between the quotes when I'm replacing the commas outside the quotes with tilde (~)?
Is there a nice efficient way to do this? Is there a common algorithm already out there that helps with this process?
Any feedback, questions, suggestions, constructive criticisms, alternatives are extremely welcome.
Please help.
Thanks in advance.
KG
01001011 01000111
I was wondering if someone could help me with this problem I have. Here is the scenario:
I have developed a Java application which allows users to upload two file types .xls and .csv. The files contain raw data. In a .csv a comma delimeter is used to determine the end of one field and the beginning of another. So for example:
12.78, sometxt,,, "123 street, city, state, zip", 13.45, "lastname, firstname",,,"company name, inc.",,
This csv file has to be converted to a tilde delimited file for another application so the result should be:
12.78~ sometxt~~~ "123 street, city, state, zip"~ 13.45~ "lastname, firstname"~~~"company name, inc."~~
The application has to verify that all the fields exist in the file, and it does this by counting the comma separators. If the criteria is not met, the file is rejected. For example if 10 fields are expected then 10 commas should be present.
Now heres the bit I'm having trouble with. When I'm doing the count for commas, how do I ignore the commas between the quotes? Also, how do I ignore the commas between the quotes when I'm replacing the commas outside the quotes with tilde (~)?
Is there a nice efficient way to do this? Is there a common algorithm already out there that helps with this process?
Any feedback, questions, suggestions, constructive criticisms, alternatives are extremely welcome.
Please help.
Thanks in advance.
KG
01001011 01000111