标题: VBS 如何替换字符?
[打印本页]
作者: huzixuan
时间: 2007-4-19 02:20
标题: VBS 如何替换字符?
a.txt 里有 :
aaaaa
aaaaa
2行字符
用 VBS 如何将 "a" 替换成 "1"
再写进 b.txt ?
我这样写却不行,应该怎么写?
set fso=CreateObject("Scripting.FileSystemObject")
set file=fso.Opentextfile("a.txt")
set fileN=fso.Createtextfile("b.txt")
str=file.readall
a=len(str)
for i=1 to a
a=mid(str,i,1)
if a = "a" then
fileN.write "1"
fileN.close
else
fileN.write a
fileN.close
end if
next
作者: estar
时间: 2007-4-19 02:24
script56.chm 搜索 replace
作者: huzixuan
时间: 2007-4-19 02:29
谢谢,刚接触 VBS 都不知道有 replace 方法.
不过之前是搜索过的 "替换字符" ,没有搜到.呵呵!
set fso=CreateObject("Scripting.FileSystemObject")
set file=fso.Opentextfile("a.txt")
set fileN=fso.Createtextfile("b.txt")
str=file.readall
strN=replace(str,"a","1")
fileN.write strN
fileN.close
作者: zhoushijay
时间: 2007-4-19 03:02
dim q,optxt,crtxt,rdtxt,a
set q=createobject("scripting.filesystemobject")
set optxt=q.opentextfile("a.txt")
set crtxt=q.createtextfile("b.txt")
rdtxt=optxt.readall
a=replace(rdtxt,"a","1")
crtxt.write a