' --------------------------------------------------------------------------' 从某一段文字中查找某一个符号(须考虑大小写),并且返回该符号的所有位置索引' douhapy 2005-01-31'' 参数:' strSentence :任意一段文字' strSymbol :需要查找的特殊符号,或字符串' SymbolIndex() :返回该符号在文字中的所处位置索引' blCaseMatch :是否必须大小写匹配 (True 大小写必须匹配)' blDesc :是否降序排列SymbolIndex中的数据(True 为降序排列索引)'' 返回值:' True 成功找到该符号,同时SymbolIndex有相应的值' --------------------------------------------------------------------------Function CheckSymbolFromSentence(ByVal strSentence As String, ByVal strSymbol As String, _ ByRef symbolIndex() As Integer, Optional ByVal blCaseMatch = True, Optional ByVal blDesc = False) As Boolean Dim intSymbolIndex() As Integer Dim strTmp As String Dim intTmp As Integer Dim blReturn As Boolean Dim i As Integer strTmp = strSentence: blReturn = False: i = 0 If blDesc Then If blCaseMatch Then intTmp = InStrRev(strTmp, strSymbol) Else intTmp = InStrRev(strTmp, strSymbol, -1, vbTextCompare) End If Else If blCaseMatch Then intTmp = InStr(strTmp, strSymbol) Else intTmp = InStr(1, strTmp, strSymbol, vbTextCompare) End If End If Do While intTmp <> 0 blReturn = True ReDim Preserve intSymbolIndex(i) intSymbolIndex(i) = intTmp intTmp = intTmp - 1 If intTmp <> 0 Then If blDesc Then If blCaseMatch Then intTmp = InStrRev(strTmp, strSymbol, intTmp) Else intTmp = InStrRev(strTmp, strSymbol, intTmp, vbTextCompare) End If Else If blCaseMatch Then intTmp = InStr(intTmp + 1, strTmp, strSymbol) Else intTmp = InStr(intTmp + 1, strTmp, strSymbol, vbTextCompare) End If End If End If i = i + 1 Loop CheckSymbolFromSentence = blReturn symbolIndex = intSymbolIndex Erase intSymbolIndexEnd Function ' --------------------------------------------------------------------------' 获取任意一段文字"( ... )"闭合符号中的字符串数据' douhapy 2005-01-31'' 参数:' strSentence :任意一段文字' LeftBracketIndex:该段文字中闭合符号左符号的索引' LeftCloseSymbol :闭合符号的左符号' RightCloseSymbol:闭合符号的右符号' blCaseMatch :是否必须大小写匹配 (True 大小写必须匹配)'' 返回值' 若成功 则返回闭合括号中的字符串' 否则 返回空字符串' --------------------------------------------------------------------------Function GetCloseString(ByVal strSentence As String, ByVal LeftBracketIndex As Integer, _ Optional ByVal LeftCloseSymbol As String = "(", Optional ByVal RightCloseSymbol As String = ")", _ Optional ByVal blCaseMatch As Boolean = True) As String Dim strReturn As String Dim strTmp As String Dim intLeftBracketIndex() As Integer ' 所有左括号的位置 Dim intRightBracketIndex() As Integer ' 所有右括号的位置 Dim i As Integer Dim j As Integer Dim m As Integer Dim mintLeftBracketIndex As Integer Dim mintRightBracketIndex As Integer strTmp = strSentence: strReturn = "" ' 查找第一个左括号 If blCaseMatch Then mintLeftBracketIndex = InStr(1, strSentence, LeftCloseSymbol) Else mintLeftBracketIndex = InStr(1, strSentence, LeftCloseSymbol, vbTextCompare) End If If mintLeftBracketIndex <> 0 Then If UCase(Mid(strSentence, LeftBracketIndex, Len(LeftCloseSymbol))) = UCase(LeftCloseSymbol) Then mintLeftBracketIndex = LeftBracketIndex End If Else GoTo EndLab End If ' 获取所有的左括号和右括号的位置 Call CheckSymbolFromSentence(strTmp, LeftCloseSymbol, intLeftBracketIndex, blCaseMatch, True) Call CheckSymbolFromSentence(strTmp, RightCloseSymbol, intRightBracketIndex, blCaseMatch, True) If UBound(intLeftBracketIndex) = UBound(intRightBracketIndex) Then ' 循环查找匹配的左右对称括号,同时将数据置为0 For i = 0 To UBoun 猜你喜欢