Read and re-write a text file

OnewayOneway Member Posts: 53
all experters

Could you guys tell me how to make this happen in code not dataport?

I have a text file SoureceFile looks like below:
A fjkmknkmn dvkmlf dklmf

B 32987329873290320932
C 987390URHIRFKJFEKKKDCM0
D 89798KNECFNKCFKLMCLMF
........................
.................

and I want to create a new text file NewFile same structure as above
but without line D. Total stream is large than 1024
notice: the second line is a blank line

Comments

  • krikikriki Member, Moderator Posts: 9,110
    "Total stream is large than 1024" : you mean that a line can be larger than 1024?
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • OnewayOneway Member Posts: 53
    Yes!
    every text line is lager than 1024
  • krikikriki Member, Moderator Posts: 9,110
    Try this:

    globals:
    Name DataType Subtype Length
    filRead File
    filWrite File
    cha Char
    intLine Integer
    filRead.WRITEMODE(FALSE);
    filRead.TEXTMODE(FALSE);
    filRead.OPEN('c:\temp\x.txt');
    
    filWrite.QUERYREPLACE(FALSE);
    filWrite.WRITEMODE(TRUE);
    filWrite.TEXTMODE(FALSE);
    filWrite.CREATE('c:\temp\xx.txt');
    
    intLine := 1;
    WHILE filRead.READ(cha) > 0 DO BEGIN
      IF cha = 13 THEN BEGIN
        // 13-10 found : end-of-line reached
        intLine += 1;
        filRead.READ(cha);
      END;
      
      // this is the line I DON'T want
      IF intLine <> 5 THEN
        filWrite.WRITE(cha);
    END;
    
    filRead.CLOSE;
    filWrite.CLOSE;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • OnewayOneway Member Posts: 53
    Thanks lots!!!

    but it seems does not work correct.
    thanks anyway.
  • krikikriki Member, Moderator Posts: 9,110
    What is not working correctly?
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.