首页 > 代码库 > GetStr: 一个自创蛮有用的字符串函数~

GetStr: 一个自创蛮有用的字符串函数~

作用:用于截取一个字符串中,两个标识符中间的字符串。 

   Public Function GetStr(ByVal InputString As String, ByVal String1 As String, ByVal String2 As String) As String

        Dim i As Integer
        Dim j As Integer
        Dim tempString As String = ""

        i = InStr(InputString, String1)
        j = InStr(i, InputString, String2)

        If i > 0 And j > 0 Then
            tempString = Mid(InputString, i + 1, j - i - 1)
        End If

        Return tempString

    End Function

例如: 取得字符串"abc(12345)test" 中的括号中的字符串 只需要写以下代码即可

samplestr = "abc(12345)test"
teststr= GetStr(samplestr, "(", ")")



GetStr: 一个自创蛮有用的字符串函数~