我是脚本新手,我不知道如何用从不同文件读取的值替换文件中的字符串。我尝试将值存储在数组中,然后将它们插入替换方法,但我无法让循环工作。这是我的两个尝试:
Const ForReading = 1
Const Inc = 0 Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("ReadInFile.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrServiceList = Split(strNextLine , ",")
Loop
Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "OrigFile.txt"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine,"777")> 0 Then
strLine = Replace(strLine,"777",arrServiceList(Inc)) Inc = Inc + 1;
End If
Loop
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set answers = fso.OpenTextFile("OrigFile.txt", ForReading)
Set fdf = fso.OpenTextFile("ReadInFile.txt", ForReading)
Set computers = CreateObject("Scripting.Dictionary")
Do Until answers.AtEndOfStream Or fdf.AtEndOfStream
computers.Add names.ReadLine, locations.ReadLine
Loop
names.Close
locations.Close
我还尝试了一个 for each 循环来读取数组,但我无法将它与另一个循环合并。