-
-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore last row if it is empty #388
Comments
This example is a 2 line CSV. It 's NOT a 3 line CSV. The line ending
denotes the end of the record.
…On Tue, 5 May 2020 at 00:05, Mark ***@***.***> wrote:
If I parse the following file with line separator ; and delimiter ,
A,B,C;\n
D,E,F;\n
the output contains three rows with the last row being an empty String[]
(note the \n).
I know this is a kind of weird csv format, however, are you considering to
support it, i.e., suppress the last line if its empty? The lib correctly
trims the last row which is \n. I know that there is an option for this,
however I don't think that it was introduced to resolve this issue, so it
rather feels like a work around.
Thank for your help and I really want to thank you for this great library!
Mark
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#388>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABWFQPX6X4XHJR4THVGPKNLRP3HBTANCNFSM4MYZ2LWQ>
.
|
Just for clarification. You say this is a two line csv, because the second line should not end with |
Ok I see what you mean. Setting the line separator to ; also requires you
to to set the normalized line ending to ;
Also disable automatic trimming of white spaces.
With that you will get the 3 rows, the last one containing the \n
Sorry for the confusion I'm working on other stuff while replying to you as
fast as I can
…On Tue, May 5, 2020, 1:29 AM Mark ***@***.***> wrote:
Just for clarification. You say this is a two line csv, because the proper
line separator is \n right?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#388 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABWFQPQUQDERM4ILKKCJDPLRP3Q4NANCNFSM4MYZ2LWQ>
.
|
I think I'm confusing you rather than the other way around and I really appreciate your quick response. So this is my problem. I have the following file semicolon.zip and run the following code.
Output: The last entry is is actually Thanks for you help once more |
Try adding this:
settings.getFormat().setNormalizedNewline('\n');
Now it won't produce that extra row with [null]. Basically this instructs
the parser to consider any \n character as a line ending, along with the
configured ';'. Note that this won't handle '\r\n'.
Hope this helps.
…On Tue, 5 May 2020 at 16:43, Mark ***@***.***> wrote:
I think I'm confusing you rather than the other way around and I really
appreciate your quick response.
So this is my problem. I have the following file semicolon.zip
<https://github.com/uniVocity/univocity-parsers/files/4579242/semicolon.zip>
and run the following code.
final CsvParserSettings settings = new CsvParserSettings();
settings..getFormat().setLineSeparator(";");
final CsvParser parser = new CsvParser(settings);
parser.beginParsing(<path to semicolon.csv>);
String row;
while((row = parser.parseNext()) != null) {
System.out.println(Arrays.toString(line)); }
Output:
[A]
[B]
[null]
The last entry is is actually \n, but due to trimming it becomes null.
What I'd prefer is that the output does not contain [null] and that's the
option I'm asking for.
Thanks for you help once more
Mark
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#388 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABWFQPRBKJMDYLMLRW7TVG3RP64C5ANCNFSM4MYZ2LWQ>
.
|
Seems like I need to make myself more familiar with the normalized Newline option. Btw. would auto-guessing the line separator resolve the Thx again for you quick reply! |
Ok now I understand I little more. Added the following two lines before creating the parser The problem is now that when I disable skipEmptyLines it returns 1 |
If I parse the following file with line separator
;
and delimiter,
A,B,C;\n
D,E,F;\n
the output contains three rows with the last row being an empty String[] (note the
\n
).I know this is a kind of weird csv format, however, are you considering to support it, i.e., suppress the last line if its empty? The lib correctly trims the last row which is
\n
. I know that there is an option for this, however I don't think that it was introduced to resolve this issue, so it rather feels like a work around.Thank for your help and I really want to thank you for this great library!
Mark
The text was updated successfully, but these errors were encountered: