正则替换
正则替换怎么用?比如我有以文件路径及文件名如:e:\\abc\cc\mm.txt
怎么通过正则替换提取文件名:mm.txt
路径是不定的。
Option Explicit Private Sub Form_Load() Debug.Print PathReplaceName(App.Path & "\test.txt", "ttx.txt") Debug.Print PathReplaceName("\test.txt", "ttx.txt") Debug.Print PathReplaceName("test.txt", "ttx.txt") End Sub Function PathReplaceName(sFile As String, sReName As String) As String Dim n&, sTemp$ n& = InStrRev(sFile, "\") sTemp$ = Mid$(sFile, 1, n&) PathReplaceName = sTemp$ & sReName End Function