本帖最后由 WHY 于 2021-1-5 23:30 编辑
回复 3# loveforjg
把 PINORDER 和 FUNCTION 之后的字符改名,把 PINSWAP 及之后的多行数据删除,多行数据判断的依据:以逗号+回车换行结束。 | Rem On Error Resume Next | | Dim reg1 | | Set reg1 = New RegExp | | reg1.Pattern = "\b(PINORDER[ \t]+)\S+" | | reg1.Global = True | | | | Dim reg2 | | Set reg2 = New RegExp | | reg2.Pattern = "\b(FUNCTION[ \t]+)\S+([ \t]+)\S+" | | reg2.Global = True | | | | Dim reg3 | | Set reg3 = New RegExp | | reg3.Pattern = "\bPINSWAP[ \t](?:[^\r\n,]|,\r\n)+(?:\r\n)?" | | reg3.Global = True | | | | Dim fso, objFile, ext | | Set fso = CreateObject("Scripting.FileSystemObject") | | | | For Each objFile In fso.GetFolder(".").Files | | ext = fso.GetExtensionName(objFile.Path) | | If LCase(ext) = "txt" Then | | replaceStr objFile.Path | | End If | | Next | | | | Function replaceStr(filePath) | | Dim f, s | | Set f = fso.OpenTextFile(filePath) | | s = f.ReadAll | | s = reg1.Replace(s, "$1NAME") | | s = reg2.Replace(s, "$1NAME$2RENAME") | | s = reg3.Replace(s, "") | | f.Close | | fso.OpenTextFile(filePath, 2, True).Write(s) | | End Function | | | | MsgBox "Done"COPY |
|