none
Hard Carriage Return in CSV file

    Question

  •  

    Hi,

    Greetings !

    I have a CSV file which I use to populate a table in VFP7.

    When I try to append from csv type csv I get one record more than the total number. On inspection of the CSV file I find that there is an HARD CARRIAGE RETURN character in one of the fields (A box like character).  When I did a ASC query I get the return answer as CHR(13). 

    I cannot replace CHR(13) using STRTRAN, then all the carriage returns are lost.

    Please advise how to remove (programatically) these unwanted characters/machine characters.

    Thanks in advance

     

    Groovy

    Friday, February 15, 2008 3:05 PM

Answers

  • If it has a chr(13), chr(10) or chr(13)+chr(10) in one of the "fields" then by definition it's not a CSV file in the first place.

     

    In your case though it might be simple to handle it. Check what normal lines end with, likely chr(13)+chr(10). Assuming it does:

     

    Code Snippet

    StrToFile(;

      strtran(

      strtran(;

      strtran(;

      strtran(;

        FileToStr('myFile.txt'),;

        chr(13)+chr(10),chr(0)),;

        chr(13),chr(1)),;

        chr(0),chr(13)+chr(10)),;

        chr(1), chr(32)), ;

      'myFile.txt')

     

    append ...

     

     

     

     

     

    Friday, February 15, 2008 3:20 PM

All replies

  • If it has a chr(13), chr(10) or chr(13)+chr(10) in one of the "fields" then by definition it's not a CSV file in the first place.

     

    In your case though it might be simple to handle it. Check what normal lines end with, likely chr(13)+chr(10). Assuming it does:

     

    Code Snippet

    StrToFile(;

      strtran(

      strtran(;

      strtran(;

      strtran(;

        FileToStr('myFile.txt'),;

        chr(13)+chr(10),chr(0)),;

        chr(13),chr(1)),;

        chr(0),chr(13)+chr(10)),;

        chr(1), chr(32)), ;

      'myFile.txt')

     

    append ...

     

     

     

     

     

    Friday, February 15, 2008 3:20 PM
  • Thanks, Cetin, for your immediate response.

    The field is  actually embedded within quotes ("), but there are other fields which contains comma,semi-colon etc and those fields are also within quotes.

    I would try your code.

    Thanks once again

     

     

    Friday, February 15, 2008 3:28 PM