Pra*_*nks 2 vbscript replace text-files
我试图从文本文件中替换3个文本.我试过这个 -
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("W:\Test.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "Aron_", "Lori_")
strNewText1 = Replace(strText, "Aron", "Jason") 'Not working
strNewText2 = Replace(strText, "Sketa", "Skicia") 'Not working
Set objFile = objFSO.OpenTextFile("W:\Test.txt", ForWriting)
objFile.WriteLine strNewText
objFile.WriteLine strNewText1 'Not working
objFile.WriteLine strNewText2 'Not working
objFile.Close
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何进行多次更换.该代码适用于单个替换功能但不超过一个... plz帮助
你需要调用Replace前面的结果Replace:
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("W:\Test.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "Aron_", "Lori_")
strNewText1 = Replace(strNewText, "Aron", "Jason")
strNewText2 = Replace(strNewText1, "Sketa", "Skicia")
Set objFile = objFSO.OpenTextFile("W:\Test.txt", ForWriting)
objFile.WriteLine strNewText2
objFile.Close
Run Code Online (Sandbox Code Playgroud)
strNewText,strNewText1,strNewText2.
strText = Replace(strText, "Aron_", "Lori_")
strText = Replace(strText, "Aron", "Jason")
strText = Replace(strText, "Sketa", "Skicia")
Run Code Online (Sandbox Code Playgroud)
然后:
objFile.WriteLine strText
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33000 次 |
| 最近记录: |