CSV File with values having single quote within quote text qualifier





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am trying to parse a CSV file which has single quote as text qualifier. The problem here is that some values with single quote text qualifier itself contains single quote
e-g:



'Fri, 24 Feb 2017 17:44:57 +0700','th01ham000tthxs','/','','Writer's Tools Data','7.1.0.0',


I am struggling to parse the file as after this row, all of the remaining rows get displaced.



I tried working with OpenCSV, UnivocityParsers but didn't get any luck.
If I place the above row in excel (Excel Image) and provide text qualifier as single quote, it give correct result without any displacement of rows.










share|improve this question


















  • 1





    if you got it working in excel sounds like you found a solution

    – Scott Holtzman
    Jan 3 at 14:59











  • But I dont know how excel handles this. I was thinking to achieve something like that from OpenCSV or UnivocityParsers as perhaps these libraries handle such sort of scenerios

    – Muhammad Salman
    Jan 3 at 19:32


















0















I am trying to parse a CSV file which has single quote as text qualifier. The problem here is that some values with single quote text qualifier itself contains single quote
e-g:



'Fri, 24 Feb 2017 17:44:57 +0700','th01ham000tthxs','/','','Writer's Tools Data','7.1.0.0',


I am struggling to parse the file as after this row, all of the remaining rows get displaced.



I tried working with OpenCSV, UnivocityParsers but didn't get any luck.
If I place the above row in excel (Excel Image) and provide text qualifier as single quote, it give correct result without any displacement of rows.










share|improve this question


















  • 1





    if you got it working in excel sounds like you found a solution

    – Scott Holtzman
    Jan 3 at 14:59











  • But I dont know how excel handles this. I was thinking to achieve something like that from OpenCSV or UnivocityParsers as perhaps these libraries handle such sort of scenerios

    – Muhammad Salman
    Jan 3 at 19:32














0












0








0


0






I am trying to parse a CSV file which has single quote as text qualifier. The problem here is that some values with single quote text qualifier itself contains single quote
e-g:



'Fri, 24 Feb 2017 17:44:57 +0700','th01ham000tthxs','/','','Writer's Tools Data','7.1.0.0',


I am struggling to parse the file as after this row, all of the remaining rows get displaced.



I tried working with OpenCSV, UnivocityParsers but didn't get any luck.
If I place the above row in excel (Excel Image) and provide text qualifier as single quote, it give correct result without any displacement of rows.










share|improve this question














I am trying to parse a CSV file which has single quote as text qualifier. The problem here is that some values with single quote text qualifier itself contains single quote
e-g:



'Fri, 24 Feb 2017 17:44:57 +0700','th01ham000tthxs','/','','Writer's Tools Data','7.1.0.0',


I am struggling to parse the file as after this row, all of the remaining rows get displaced.



I tried working with OpenCSV, UnivocityParsers but didn't get any luck.
If I place the above row in excel (Excel Image) and provide text qualifier as single quote, it give correct result without any displacement of rows.







excel csv opencsv univocity






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 14:52









Muhammad SalmanMuhammad Salman

63




63








  • 1





    if you got it working in excel sounds like you found a solution

    – Scott Holtzman
    Jan 3 at 14:59











  • But I dont know how excel handles this. I was thinking to achieve something like that from OpenCSV or UnivocityParsers as perhaps these libraries handle such sort of scenerios

    – Muhammad Salman
    Jan 3 at 19:32














  • 1





    if you got it working in excel sounds like you found a solution

    – Scott Holtzman
    Jan 3 at 14:59











  • But I dont know how excel handles this. I was thinking to achieve something like that from OpenCSV or UnivocityParsers as perhaps these libraries handle such sort of scenerios

    – Muhammad Salman
    Jan 3 at 19:32








1




1





if you got it working in excel sounds like you found a solution

– Scott Holtzman
Jan 3 at 14:59





if you got it working in excel sounds like you found a solution

– Scott Holtzman
Jan 3 at 14:59













But I dont know how excel handles this. I was thinking to achieve something like that from OpenCSV or UnivocityParsers as perhaps these libraries handle such sort of scenerios

– Muhammad Salman
Jan 3 at 19:32





But I dont know how excel handles this. I was thinking to achieve something like that from OpenCSV or UnivocityParsers as perhaps these libraries handle such sort of scenerios

– Muhammad Salman
Jan 3 at 19:32












2 Answers
2






active

oldest

votes


















0














If using java, the JRecord library should handle the File.



How it works: if a field starts with a quote (e.g. ,') specifically look for ', or ''', or ''''', or ' etc (an odd number of quotes followed by either a comma or end-of-line marker). This approach breaks down if:




  • The embedded quote is the last character in a field i.e. 'Field with quote '',

  • White space between the quote and comma i.e. 'Field' , or , '


Here is the line in ReCsvEditor



ReCsvEditor





Also in the ReCsvEditor when editing the file, if you select Generate >>> Java Code >>> ... it will generate Java/JRecord Code to read the file.



ReCsvEditor Generate



Disclaimer: I am the author of JRecord / ReCvEditor. Also the ReCsvEditor Generate function is new and needs more work






share|improve this answer































    0














    Try configuring univocity-parsers to handle the unescaped quote according to your scenario. 'Writer's Tools Data' has an unescaped quote. From your input, I can see you want to use STOP_AT_CLOSING_QUOTE as the strategy to work around these values.



    Add this line to your code and it should work fine:



    parserSettings.setUnescapedQuoteHandling(UnescapedQuoteHandling.STOP_AT_CLOSING_QUOTE);


    Hope this helps.






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024681%2fcsv-file-with-values-having-single-quote-within-quote-text-qualifier%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      If using java, the JRecord library should handle the File.



      How it works: if a field starts with a quote (e.g. ,') specifically look for ', or ''', or ''''', or ' etc (an odd number of quotes followed by either a comma or end-of-line marker). This approach breaks down if:




      • The embedded quote is the last character in a field i.e. 'Field with quote '',

      • White space between the quote and comma i.e. 'Field' , or , '


      Here is the line in ReCsvEditor



      ReCsvEditor





      Also in the ReCsvEditor when editing the file, if you select Generate >>> Java Code >>> ... it will generate Java/JRecord Code to read the file.



      ReCsvEditor Generate



      Disclaimer: I am the author of JRecord / ReCvEditor. Also the ReCsvEditor Generate function is new and needs more work






      share|improve this answer




























        0














        If using java, the JRecord library should handle the File.



        How it works: if a field starts with a quote (e.g. ,') specifically look for ', or ''', or ''''', or ' etc (an odd number of quotes followed by either a comma or end-of-line marker). This approach breaks down if:




        • The embedded quote is the last character in a field i.e. 'Field with quote '',

        • White space between the quote and comma i.e. 'Field' , or , '


        Here is the line in ReCsvEditor



        ReCsvEditor





        Also in the ReCsvEditor when editing the file, if you select Generate >>> Java Code >>> ... it will generate Java/JRecord Code to read the file.



        ReCsvEditor Generate



        Disclaimer: I am the author of JRecord / ReCvEditor. Also the ReCsvEditor Generate function is new and needs more work






        share|improve this answer


























          0












          0








          0







          If using java, the JRecord library should handle the File.



          How it works: if a field starts with a quote (e.g. ,') specifically look for ', or ''', or ''''', or ' etc (an odd number of quotes followed by either a comma or end-of-line marker). This approach breaks down if:




          • The embedded quote is the last character in a field i.e. 'Field with quote '',

          • White space between the quote and comma i.e. 'Field' , or , '


          Here is the line in ReCsvEditor



          ReCsvEditor





          Also in the ReCsvEditor when editing the file, if you select Generate >>> Java Code >>> ... it will generate Java/JRecord Code to read the file.



          ReCsvEditor Generate



          Disclaimer: I am the author of JRecord / ReCvEditor. Also the ReCsvEditor Generate function is new and needs more work






          share|improve this answer













          If using java, the JRecord library should handle the File.



          How it works: if a field starts with a quote (e.g. ,') specifically look for ', or ''', or ''''', or ' etc (an odd number of quotes followed by either a comma or end-of-line marker). This approach breaks down if:




          • The embedded quote is the last character in a field i.e. 'Field with quote '',

          • White space between the quote and comma i.e. 'Field' , or , '


          Here is the line in ReCsvEditor



          ReCsvEditor





          Also in the ReCsvEditor when editing the file, if you select Generate >>> Java Code >>> ... it will generate Java/JRecord Code to read the file.



          ReCsvEditor Generate



          Disclaimer: I am the author of JRecord / ReCvEditor. Also the ReCsvEditor Generate function is new and needs more work







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 3 at 22:32









          Bruce MartinBruce Martin

          8,39211632




          8,39211632

























              0














              Try configuring univocity-parsers to handle the unescaped quote according to your scenario. 'Writer's Tools Data' has an unescaped quote. From your input, I can see you want to use STOP_AT_CLOSING_QUOTE as the strategy to work around these values.



              Add this line to your code and it should work fine:



              parserSettings.setUnescapedQuoteHandling(UnescapedQuoteHandling.STOP_AT_CLOSING_QUOTE);


              Hope this helps.






              share|improve this answer




























                0














                Try configuring univocity-parsers to handle the unescaped quote according to your scenario. 'Writer's Tools Data' has an unescaped quote. From your input, I can see you want to use STOP_AT_CLOSING_QUOTE as the strategy to work around these values.



                Add this line to your code and it should work fine:



                parserSettings.setUnescapedQuoteHandling(UnescapedQuoteHandling.STOP_AT_CLOSING_QUOTE);


                Hope this helps.






                share|improve this answer


























                  0












                  0








                  0







                  Try configuring univocity-parsers to handle the unescaped quote according to your scenario. 'Writer's Tools Data' has an unescaped quote. From your input, I can see you want to use STOP_AT_CLOSING_QUOTE as the strategy to work around these values.



                  Add this line to your code and it should work fine:



                  parserSettings.setUnescapedQuoteHandling(UnescapedQuoteHandling.STOP_AT_CLOSING_QUOTE);


                  Hope this helps.






                  share|improve this answer













                  Try configuring univocity-parsers to handle the unescaped quote according to your scenario. 'Writer's Tools Data' has an unescaped quote. From your input, I can see you want to use STOP_AT_CLOSING_QUOTE as the strategy to work around these values.



                  Add this line to your code and it should work fine:



                  parserSettings.setUnescapedQuoteHandling(UnescapedQuoteHandling.STOP_AT_CLOSING_QUOTE);


                  Hope this helps.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 8 at 13:46









                  Jeronimo BackesJeronimo Backes

                  4,42511624




                  4,42511624






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024681%2fcsv-file-with-values-having-single-quote-within-quote-text-qualifier%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      MongoDB - Not Authorized To Execute Command

                      How to fix TextFormField cause rebuild widget in Flutter

                      in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith