以下是我已写过的脚本的一部分:
For i = 1 to arrsize
strText=""
Set objFile = objFSO.OpenTextFile(filetable(i), ForReading)
wscript.echo filetable(i)
On Error Resume Next
Do Until objFile.AtEndOfStream
strline = objFile.ReadLine
If instr(strline, source_string) > 0 Then
wscript.echo strline
Do Until instr(strline, " TEXT ") > 0 or instr(strline, Chr(9) & "TEXT ")
strline = objFile.ReadLine
Loop
strNewText = Replace(strline, "TEXT " & Chr(34), "TEXT " & Chr(34) & "Critical: ",1,-1,0)
wscript.echo strNewText
'up to here everything is OK
Set objFile = objFSO.OpenTextFile(filetable(i), ForWriting)
objFile.WriteLine strNewText
objFile.close
'The three line above are overwriting the text file
End If`enter code here`
Loop
Next
我的脚本是在一个文件数组中搜索在source_string变量中注册的特定字符串,然后如果它匹配则应该搜索" TEXT"以空格或制表符开头的单词,当匹配时,它应该根据以下格式替换具有相同行的行: 文字"关键:****"。 我希望它很清楚,并感谢先进的
答案 0 :(得分:1)
我想在这里你再次打开文本文件,然后从流的开头开始,从而开始第一行(而不是找到的行):
Set objFile = objFSO.OpenTextFile(filetable(i), ForWriting)
objFile.WriteLine strNewText
objFile.close
也许您应该尝试打开文件进行阅读和写作,阅读,找到str后,然后更改该行并继续...
答案 1 :(得分:0)
For i = 1 to arrsize
Set objFile = objFSO.OpenTextFile(filetable(i), ForReading)
wscript.echo filetable(i)
On Error Resume Next
Dim filearray()
Linenb = 0
Do Until objFile.AtEndOfStream
Linenb = Linenb + 1
Redim Preserve filearray(Linenb)
filearray(Linenb) = objFile.ReadLine
' wscript.echo filearray(Linenb)
If instr(filearray(Linenb), source_string) > 0 Then
' wscript.echo filearray(Linenb)
Do Until instr(filearray(Linenb), " TEXT ") > 0 or instr(filearray(Linenb), Chr(9) & "TEXT ")
Linenb = Linenb + 1
Redim Preserve filearray (Linenb)
filearray(Linenb) = objFile.ReadLine
' wscript.echo filearray(Linenb)
Loop
filearray(Linenb) = Replace(filearray(Linenb), "TEXT " & Chr(34), "TEXT " & Chr(34) & "Critical: ",1,-1,0)
' wscript.echo filearray(Linenb)
End If
Loop
For j = 1 to Linenb
Set objFile = objFSO.OpenTextFile(filetable(i), ForWriting)
objfile.WriteLine filearray(j)
Next
Redim Preserve filearray (1)
下一步