Forum Discussion

kimmatsumoto's avatar
kimmatsumoto
Contributor
7 years ago

How do I remove a datetime stamp from a text file?

How do I remove the datetime stamp from the following text file?

 

"SYSDBA","05/17/2017 1:09:40 PM","Update","","BRANCH","1","0"

 

 

Thanks,

Kim

10 Replies

    • kimmatsumoto's avatar
      kimmatsumoto
      Contributor

      Hi...thanks to everyone for their help.  It was suggested that I include what I'm trying to achieve...

      I'm writing the contents of a grid to a text file (notepad) which will be used as a baseline during a file compare. The problem is the file includes a datetime stamp which will cause the file comparison to always fail.  

       

      The notepad file looks like this: "SYSDBA","05/17/2017 1:09:40 PM","Update","","BRANCH","1","0"

      My goal is to end up with a file looking like one of the following:

      "Update","","BRANCH","1","0"

      "SYSDBA","Update","","BRANCH","1","0"

       

      This is a copy of the code I'm using:

      procedure Test;
      var
        tempFileName4, FileName4, str : OleVariant;
      begin
        tempFileName4 := Project.Path + '4199_4_temp.txt';

       //Save 2nd row in listview to file
       listview := TBO.HistoryForm.CDSListView1;
       ListViewItemToCSVFile4(listview, tempFileName4, 1);
       //Verify 2nd item displays: BRANCH (field), 1 (Old Value), 0 (New Value)
       if Files.Compare(FileName4, tempFileName4) then
        log.Checkpoint(tempFileName4+' matches baseline.');

      end;

       

      Thanks in advanced,

      Kim

      • shankar_r's avatar
        shankar_r
        Community Hero

        Hi,

         

        ListViewItemtoCSVFile4 is writing output value to a tempFilename4

         

        Then you are comparing tempFileName4 with FileName4.

         

        If my understanding is correct,

         

        FileName4 will have the contents with Timestamp and tempFileName4 will not have the timestamp

         

        So, Checkpoint going fail in this scenario.

         

        Correct me if my understanding is wrong

         

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

     

    you can use below function to phrase your text input, there couple of ways to remove the date and time.

     

    1. As

     

     

    function convertTime()
    {
          var sampleString = aqFile.ReadWholeTextFile("D:\\CommunityDay\\sample.txt",20);
          
          
          aqString.ListSeparator = ","; 
               
          if(sampleString != "")
          {
                for(var i = 0 ; i < aqString.GetListLength(sampleString) ; i++)
                {
                      //if(Rgular expression match for date format)
                      //{
                       Log.Message(aqString.GetListItem(sampleString,i));
                      //} 
                }
          } 
          
    } 
    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Considering the file is formatted much like a CSV, you could use DDT.CSVDriver to read out the values of the file and then rewrite them to a new file, making sure that, when you write the date column that you just leave it blank.

       

      You could use aqFile.OpenTextFile to open the file and then, in a while loop on EOF, read each line, use aqString.GetListItem as mentioned before to parse out the date, and then re-write the file.  

       

      Any one of these methods would work just as well as any other.  Personally, I don't like regular expressions so, since the file has a structure that allows it, the GetListItem or CSV method would be my preferred ways.

  • NisHera's avatar
    NisHera
    Valued Contributor

    Hi,

    This would be much complicated.

    you have to read entire file to a string variable , select date format in this variable using Regex.

    Then re write the file.

    But if you tell us what you are trying to achieve (the context of your problem ) there may be more simple solutions.