Board logo

标题: 一个简单的查找替换要求 [打印本页]

作者: hxg123     时间: 2006-8-31 18:05    标题: 一个简单的查找替换要求
我想在一个文本中找多个内容并替换,如何操作?
如:
A.txt

ASDSDKKASKDKASD,BAJSDKKSDSDLSDBB


要求查找A.txt中的A,用D替换;查找B,用F替换。

作者: namejm     时间: 2006-8-31 21:30
  类似的问题论坛里已经有过比较多的讨论,请多用论坛的搜索功能查找你想要的答案,多潜水翻看旧帖是逛论坛的好习惯。

  怎么利用批处理替换文本文件中的指定内容 http://www.cn-dos.net/forum/viewthread.php?tid=22033&fpage=1&highlight=%E6%9B%BF%E6%8D%A2

作者: piziliu2004     时间: 2006-9-1 10:51
Function SearchFile(filespec)
Const ForReading = 1,ForWriting=2
Dim fso, theFile, retchar(80),i
i=0
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(filespec, ForReading, False)
Do While theFile.AtEndOfLine <> True
retchar(i) =theFile.Read(1)
i=i+1
Loop
Maxrow=i
theFile.Close

For i=0 To Maxrow
if retchar(i)="A" then
retchar(i)="D"
End If
if retchar(i)="B" then
retchar(i)="F"
End If
Next
Set theFile = fso.OpenTextFile(filespec, ForWriting, False)
For i=0 to Maxrow
theFile.write(retchar(i))
Next
End Function

这个是最原始算法.. 可以用replace更方便