vbs“通配符”问题...

2025-03-02 10:07:24
推荐回答(1个)
回答1:

replace不支持通配符。可以使用正则表达式。
------------------------------------------
既然没有样本就将就用吧:

strFile = "1.txt"
oFile = "2.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, 1)

Do While not objFile.AtEndOfStream
strLine = objFile.ReadLine
If Instr(strLine,"1313") > 0 Then
strLine = Replace(strLine,"asdfa1313","2221313")
strLine = Replace(strLine,"45647561313","2221313")
strLine = Replace(strLine,"1u2j%1313","2221313")
Else
strLine = strLine
End If
colLines = colLines & strLine & vbCrLf
Loop
objFile.Close

Set objFile = objFSO.CreateTextFile(oFile, True)
objFile.Write colLines
objFile.Close

Set objFSO = Nothing