wenquan
新手上路
积分 3
发帖 3
注册 2009-8-10
状态 离线
|
『楼 主』:
VBS 将1.txt内容续行在2.txt查找是否存在,有则改
大家好!关于用VBS脚本替换特定的字符问题,请帮忙指点指点,谢谢!
要求:如题,用VBS 将1.txt内容续行在2.txt查找是否存在,有就将改为逗号",",若没有就将其保存在3.txt中。
我要网上有搜到line.VBS 是续行读取并显示的脚本,change.vbs 是关于特定字符替换的脚本,但我不知道怎么将其整合在一起,达到自己想要功能。
---1.txt--
C62,
c770,
c758,
c764,
c760,
c63,
c6,
c754,
c744,
c25,
c1,
c14,
c4,
cr75,
c766,
c7,
c8,
c99,
c56,
c725,
c256,
--2.txt---
035-0012-000 CAP SCD EC07 C0G 0402 100pF 50V 5% C62,
035-0011-000 CAP SCD EC07 C0G 0402 10pF 50V 5% "C768,C769,C770,C758,C763,C764,"
035-0020-000 CAP SCD EC07 C0G 0402 18pF 50V 5% "C759,C760,C761,C63,C64,C753,C754,C755,"
035-0024-000 CAP SCD EC07 C0G 0402 220pF 50V 5% "C733,C25,C1,C14"
035-0023-000 CAP SCD EC07 C0G 0402 22pF 50V 5% "C4,C5,C765,C766"
035-0066-000 CAP SCD EC07 C0G 0402 330pF 50V 5% C533,
035-0039-000 CAP SCD EC07 C0G 0603 10pF 50V 5% "C7,C8,C749,C752,"
039-0024-000 CAP SCD EC07 X5R 0402 .01uF 16V 10% "C717,C732,C737,"
039-0006-000 CAP SCD EC07 X5R 0402 .01uF 6V 10% "C56,C596,C598,C606,C625,C725,"
---line.vbs---
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("a.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.ReadLine
Wscript.Echo strComputer
Loop
objTextFile.Close
---change.vbs---
'定义所用的变量
Dim fso,file,text1,text2,file0,content
Set fso=CreateObject("scripting.filesystemobject")
'防止出错
On Error Resume Next
file = InputBox ("请你输入文本的路径","方窗制作")
text1 = InputBox ("请输入要替换的字节","方窗制作")
text2 = InputBox ("请输入替换后的字节","方窗制作")
Set file0 = fso.Opentextfile(file, 1, false)
content = file0.readall
'替换字节函数
Function ReplaceTest(text, patrn, replStr)
Dim regEx, str1 '建立函数变量
str1 = text '要更改的文本字段
Set regEx = New RegExp '建立正则表达式
regEx.Pattern = patrn '设置要替换的字符
regEx.IgnoreCase = True '设置是否区分大小写
ReplaceTest = regEx.Replace(str1, replStr) '作替换
End Function
'写出文本函数
Function Writetext(text)
Set text0= fso.openTextFile(file&"已替换.txt",2,true)
text0.writeline text
End Function
'同时调用双函数
Writetext(ReplaceTest(content,text1,text2))
MsgBox "恭喜你已经替换成功",,"方窗制作"
[ Last edited by wenquan on 2009-9-13 at 09:31 ]
|
|