我一直在使用Notepad ++来调整TXT文件。我想知道是否可以使用VBScript自动执行此操作?
\r\n
替换为“”(空格)。I0
替换为\nI0
。X0
替换为\nI0
。答案 0 :(得分:0)
以下示例适用于Unicode和ASCII文本文件:
sPath = "C:\Users\DELL\Desktop\tmp\test.txt"
sContent = ReadTextFile(sPath, 0) ' lFormat -2 - System default, -1 - Unicode, 0 - ASCII
sContent = Replace(sContent, vbCrLf, " ")
sContent = Replace(sContent, "I0", vbLf & "I0")
sContent = Replace(sContent, "X0", vbLf & "I0")
WriteTextFile sContent, sPath, 0
Function ReadTextFile(sPath, lFormat)
With CreateObject("Scripting.FileSystemObject").OpenTextFile(sPath, 1, False, lFormat)
ReadTextFile = ""
If Not .AtEndOfStream Then ReadTextFile = .ReadAll
.Close
End With
End Function
Sub WriteTextFile(sContent, sPath, lFormat)
With CreateObject("Scripting.FileSystemObject").OpenTextFile(sPath, 2, True, lFormat)
.Write sContent
.Close
End With
End Sub