You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Santhsoh (Jira)" <ji...@apache.org> on 2021/09/03 08:49:00 UTC

[jira] [Commented] (CSV-206) Add support for String delimiters #76

    [ https://issues.apache.org/jira/browse/CSV-206?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17409380#comment-17409380 ] 

Santhsoh commented on CSV-206:
------------------------------

Hi All,
I was testing the functionality to use string delimiter and found the following issue.

 

{{}}
{code:java}
<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-csv</artifactId> <version>1.9.0</version> </dependency>{code}
{{}}
{code:java}
public static void main(String[] args) throws Exception{
     String row = "a||b||c||d||||f||g";
     StringBuilder stringBuilder = new StringBuilder();
     try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL);
          CSVParser csvParser = CSVParser.parse(new StringInputStream(row), StandardCharsets.UTF_8, CSVFormat.Builder.create().setDelimiter("||").build())) {
         for (CSVRecord csvRecord : csvParser) {
             for (int i = 0; i < csvRecord.size(); i++) {
                 csvPrinter.print(csvRecord.get(i));
             }
             System.out.println(stringBuilder.toString());
             //Expected : a,b,c,d,,f,g
            // Actual : a,b|c,d,|f,g
         }
     }
 }
{code}
{{}}The actual value is different from expected, looks like the string delimiter doesn't work as expected when there is an empty column.

 

> Add support for String delimiters #76
> -------------------------------------
>
>                 Key: CSV-206
>                 URL: https://issues.apache.org/jira/browse/CSV-206
>             Project: Commons CSV
>          Issue Type: Improvement
>            Reporter: jefferyyuan
>            Priority: Major
>              Labels: commons, commons-csv, csv, csvparser
>             Fix For: 1.9.0
>
>          Time Spent: 3h
>  Remaining Estimate: 0h
>
> It's not uncommon that we use multiple-characters delimiter to separate columns in CVS: such as: [|]
> Sometimes, we have no choice as third-party defines the csv format like that.
> It would be great if apache commons.csv supports this function.
> I did some google search: seems there is no java library that supports use multiple-characters as the column separator.
> But the C# CsvHelper does
> https://github.com/JoshClose/CsvHelper



--
This message was sent by Atlassian Jira
(v8.3.4#803005)