Results 1 to 2 of 2

Thread: Getting a string from a text file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    UK
    Posts
    66
    What would be the best way to open a text file, find a string, delete it, perform an action then add the string back to the text file? !!!

    ie

    open text file
    find "wibble"
    if it exists - delete it
    close text file

    perform some action

    open text file
    add "wibble"
    close text file

    Any ideas people?
    Simon

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I didn't test it but try this out:

    'This will open a file:

    Open filename For Binary As #1
    File = Space(LOF(#1))
    Get #fnum, , filevar
    Close #1


    'And this will search it for the string and remove it:

    a=instr(filevar,string)
    filevar=left(filevar,a-1) & mid(filevar,a+len(string))

    'This will put it back in the file

    Open filename For Binary As #1
    Put #1, , filevar
    Close #1

    'This will add string

    Open filename for append as #1
    Print#1, string;
    close #1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width