有什么简单的方法只保留下TXT文档中的括号部分
来源:百度知道 编辑:UC知道 时间:2024/05/28 09:35:21
1、TXT文档中有非常多被小括号括起来的内容;2、notepad++同一行只能留下一对括号,不可以。
二楼的方法非常好,可惜好象不支持中文,中文部分都成为乱码。
sFile = "1.txt"
pFile = "2.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = objFSO.OpenTextFile(sFile, 1)
colLines = oFile.ReadAll
oFile.Close
Set objRegEx = CreateObject("VBSCript.RegExp")
objRegEx.Global = True
objRegEx.IgnoreCase = True
objRegEx.Pattern = "\(.*\)"
Set Matches = objRegEx.Execute(colLines)
For Each Match in Matches
oMatches = oMatches & Match & vbCrLf
oMatches = Replace(Replace(oMatches, ")", ")" & vbCrLf),"(",vbCrLf & "(" )
Next
oMatches = Split(oMatches, vbCrLf)
For Each oMatch in oMatches
If Instr(oMatch,"(") > 0 Then
colMatches = colMatches & oMatch & vbCrLf
End If
Next
Set oFile = objFSO.CreateTextFile(pFile, True)
oFile.Write colMatches
oFile.Close