Parse a text file containing quotation marks
We have a semicolon-separated csv file. Its first column is enclosed by double quotation marks and also contains semicolons.
cars;countries;grades;color;speed "car1;car2;car3;car4;car5;car6;car7;car8;car8";USA;26;green;230 "car11;car12;car13;car14;car15;car16;car17;car18;car18";CHINA;23;red;190 |
Task: Use Java to parse the csv file as a standard two-dimensional table for the convenience of later querying.
cars |
countries |
grades |
color |
speed |
|
1 |
"car1;car2;car3;car4;car5;car6;car7;car8;car8" |
USA |
26 |
green |
230 |
2 |
"car11;car12;car13;car14;car15;car16;car17;car18;car18" |
CHINA |
23 |
red |
190 |
Write the following SPL code:
=file(\"data.csv\").import@tp(;,\";\")
import()function parses the text file as a two-dimensional table; @t enables importing column headers, and @p enables to handle matching of special characters (quotation marks and parentheses), except for the internal separators, during parsing.
Read How to Call a SPL Script in Java to find how to integrate SPL into a Java application.
Source: https://stackoverflow.com/questions/72412780/reading-csv-files-when-having-double-quotes-in-a-value
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL