Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Location
    South Africa
    Posts
    178

    Question Unanswered: search and replace

    Hi All

    I have a db that exports a report to a text file.
    Once that is done, I need to do a 'search and replace' on the text file to find a "*" and replace it with a " ". I know I can do it from the text file itself, but i need to have it automated. I have code that exports to the text file. Is there code that I can add after that, that will do a search and replace on the textfile?

  2. #2
    Join Date
    Feb 2004
    Location
    Dorset UK
    Posts
    147
    Could try this:


    Your_Output_file = "c:\test.txt"
    Your_New_Output_file = "c:\test1.txt"

    Dim fs, a
    Dim Get_Text, New_Text

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.OpenTextFile(Your_Output_file)

    Do While a.AtEndOfStream <> True
    Get_Text = a.Readall
    Loop
    a.Close

    New_Text = Replace(Get_Text, "*", "#", 1, -1, vbTextCompare)

    Set a = fs.CreateTextFile(Your_New_Output_file, True)
    a.WriteLine New_Text
    a.Close


    I don't know the full limitations of the writeline, but it certain works on my test file.

    There may be a better way, but this seems to work.

    ALSO if you want to overwrite the original file, you can either change the variable three lines from the bottom to your_output_file or change the names at the top.

    The reason I gave them different names is so that I could check what was done.

    Hope this helps you in your quest!!

    Regards

    Ken


  3. #3
    Join Date
    Jan 2004
    Location
    South Africa
    Posts
    178
    thats fantastic!
    didn't think I'd get that to work.

    thanks
    ActionAnt

Posting Permissions

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