Refer to GPT and your own ideas. When working with data that contains delimiters, consider using escape characters to distinguish between commas in data and commas of delimiters. In general, CSV files use double quotes to contain data that contains delimiters, and use commas within double quotes not as delimiters, such as:
1,2,"3,4",5
In the above data, the comma delimiter is comma, while the comma in data "3,4" is enclosed in double quotes and is not treated as a delimiter.
In Java, you can use double quotes to contain data that contains commas and double quotes to escape the double quotes within it, such as:
String data = "1,2,\"3,4\",5";
If the data itself contains double quotes, you need to escape it to two double quotes, for example:
String data = "1,2,\"3,\"\"4\",5";
When writing to a CSV file, you can use commas as delimiters, double quotes to contain data that contains commas, and add a double quote before a double quote that needs to be escaped, for example:
String[] row = {"1", "2", "3,4", "5"};
String line = String.join(",", Arrays.stream(row).map(s -> "\"" + s.replace("\"", "\"\"") + "\"").toArray(String[]::new));
The code above concatenates the data in the array row into a string with commas, wraps the data containing the commas in double quotes, and adds a double quote before the double quote that needs to be escaped. The resulting string is:
1,2,"3,4",5
If it helps you, please give it, thank you.