I have an HTML page with one or more newlines after </html>. My VBScript file is able to find the replace the newlines with emptiness. But, it looks like OpenTextFile is putting a newline at the end again. Help!
'Pulled this from the InterWebs
Const ForReading = 1 Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("a.html", ForReading)
strText = objFile.ReadAll
'Wscript.Echo strText
objFile.Close
strNewText = Replace(strText, "</html>" & vbCrlf, "</html>")
Set objFile = objFSO.OpenTextFile("a.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Instead of objFile.WriteLine strNewText use objFile.Write strNewText. This will write the file without a newline at the end.
BTW, another way of removing the newline(s) from after your </html> tag would be strNewText = Trim(strText) instead of using Replace()
This may help:
The TextStream object has the following important methods for writing to text files:
If you do not want a newline at the end, use
objFile.Write strNewText
instead of
objFile.WriteLine strNewText
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With