Results 1 to 4 of 4

Thread: Searching/Editing Textfile

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    181

    Searching/Editing Textfile

    Hi

    I am writing a piece of code using the FileSystemObject... it copies a plain text file... however, I need to search for a string in that text file and replace it (in the copied version) with another string and I have absolutely no idea how to do this... any ideas? I can copy the file, just not search & edit it

    Thanks,

    Adam

  2. #2
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Here is a solution, read the file in to a string variable, then do a replace on the string and then write the string to the new file.
    VB Code:
    1. 'open your file, etc
    2. strFile = f.ReadAll
    3. strFile = Replace(strFile, "whatever", "new stuff")
    4. 'write strFile back to the new file
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    181
    Will that replace just the first match, or all of them?

    Either way, thanks

    Adam

  4. #4
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    All of them.
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


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