本帖最后由 apang 于 2014-7-8 14:14 编辑
- Dim str, fso, file, f, txt
- str = "零一二三四五六七八九十百千"
- Set fso = CreateObject("Scripting.FileSystemObject")
- For Each file in fso.GetFolder(".").Files
- If LCase(Right(file, 4)) = ".txt" Then
- Set f = fso.OpenTextFile(file, 1)
- txt = f.ReadAll
- f.Close : Set f = Nothing
- fso.OpenTextFile(file, 2).Write RegEx(txt)
- End If
- Next
- Set fso = Nothing
-
- MsgBox "OK"
-
- Function RegEx(txt)
- Dim re, s, i, s1, ss
- Set re = New RegExp
- re.Pattern = "(第)([" & str & "]+)(节)"
- If Not re.Test(txt) Then RegEx = txt : Exit Function
- s = re.Execute(txt)(0).SubMatches(1)
- If Left(s, 1) = "十" Then s = "一" & s
- For i = 1 to Len(s)
- s1 = Mid(s, i, 1)
- If InStr(str, s1) > 10 Then
- ss = ss & "*10^" & (InStr(str, s1)-10) & "+"
- Else ss = ss & (InStr(str, s1)-1)
- End If
- Next
- s = Right("0000" & eval(ss & "+0"), 4)
- RegEx = re.Replace(txt, "$1" & s & "$3")
- End Function
复制代码 第2个,把function部分换成:- Function RegEx(txt)
- Dim re, s
- Set re = New RegExp
- re.Pattern = "【(\d+)】"
- If Not re.Test(txt) Then RegEx = txt : Exit Function
- s = re.Execute(txt)(0).SubMatches(0)
- s = Right("0000" & s, 4)
- RegEx = re.Replace(txt, "第" & s & "节")
- End Function
复制代码
|