'*********************************************************** '函数说明:在源字符中截取在strBegin 和 strEnd 之间的字符 '参数说明:默认为 True '调用例子:strTemp = GetBetWeen("中[国]人","[","]",true ) 结果:[国] '调用例子:strTemp = GetBetWeen("中[国]人","[","]",false) 结果:国 '*********************************************************** 'Arr(1) = GetBetWeen(Text, "入账日期", "│", False) Public Function StringBetween(ByRef strInput As Variant, ByVal strBegin As String, ByVal StrEnd As String, Optional Flag As Boolean = True) Dim Text As String Dim TopPos As Integer '开始点 Dim EndPos As Integer '结束点 Dim strLen As Integer '字符长度 TopPos = InStr(1, strInput, strBegin, vbTextCompare) If TopPos > 0 Then 'strResult = Mid(strInput, intFound + Len(strBegin)) 'Text = Mid(strInput, TopPos) EndPos = InStr(TopPos + Len(strBegin), strInput, StrEnd, vbTextCompare) If EndPos > 0 Then If Flag Then TopPos = TopPos EndPos = EndPos + Len(StrEnd) Else TopPos = TopPos + Len(strBegin) EndPos = EndPos End If Text = Trim(Mid(strInput, TopPos, EndPos - TopPos)) End If End If StringBetween = Text End Function