VBScript 删除换行符

pub*_*avi 2 vbscript

我有一个 HTML 页面,其后有一个或多个换行符</html>。我的 VBScript 文件能够找到用空值替换换行符。但是,看起来 OpenTextFile 又在末尾添加了换行符。帮助!

'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
Run Code Online (Sandbox Code Playgroud)

小智 5

而不是objFile.WriteLine strNewText使用objFile.Write strNewText. 这将写入文件末尾不带换行符。

顺便说一句,从标签后删除换行符的另一种方法</html>strNewText = Trim(strText)而不是使用Replace()