Saving to file adds extra line

Author Message
ratsvbs

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 11/23/2011
  • Status: offline
Saving to file adds extra line Wednesday, November 23, 2011 9:32 AM (permalink)
0
Hi all,
 
My first post here :-)
 
I'm trying to open a file and do a find and replace on some contents and then save to a new file. The actual find and replace portion works fine except when saving to a new file I get an extra line added to the end of the file. Does anyone know why an extra line is added and how I can remove it?
My code follows.
Thanks
 
Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\testin.log", ForReading)

strText = objFile.ReadAll
strNewText = Replace(strText, "ddmmyy", "241111")

Set objFile = objFSO.CreateTextFile("c:\testout.log")
objFile.WriteLine strNewText
objFile.Close
 
#1
    59cobalt

    • Total Posts : 979
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:Saving to file adds extra line Wednesday, November 23, 2011 9:55 AM (permalink)
    0
    ratsvbs
    I'm trying to open a file and do a find and replace on some contents and then save to a new file. The actual find and replace portion works fine except when saving to a new file I get an extra line added to the end of the file. Does anyone know why an extra line is added and how I can remove it?
    [...]'...
    objFile.WriteLine strNewText[/code]
    Perhaps surprisingly, WriteLine() behaves exactly as documented: it writes the given string followed by a newline. Change WriteLine to Write, and your problem will disappear.
     
    #2
      ratsvbs

      • Total Posts : 2
      • Scores: 0
      • Reward points : 0
      • Joined: 11/23/2011
      • Status: offline
      Re:Saving to file adds extra line Wednesday, November 23, 2011 10:03 AM (permalink)
      0
      Indeed A fool I am. :-(

      Thanks for your help.
       
      #3
        59cobalt

        • Total Posts : 979
        • Scores: 91
        • Reward points : 0
        • Joined: 7/17/2011
        • Status: offline
        Re:Saving to file adds extra line Wednesday, November 23, 2011 10:21 AM (permalink)
        0
        You're welcome.
         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9