Get the value between the brackets

后端 未结 4 1787
感情败类
感情败类 2021-01-12 05:02

I have a column with some stuff that looks like the following string: V2397(+60)

How do I get the value between the brackets? In this case the +60

4条回答
  •  清歌不尽
    2021-01-12 06:00

    Thanks to Andrew Cooper for his answer.

    For anyone interested I refactored into a function...

     Private Function GetEnclosedValue(query As String, openingParen As String, closingParen As String) As String
        Dim pos1 As Long
        Dim pos2 As Long
    
        pos1 = InStr(query, openingParen)
        pos2 = InStr(query, closingParen)
    
        GetEnclosedValue = Mid(query, (pos1 + 1), (pos2 - pos1) - 1)
    End Function
    

    To use

    value = GetEnclosedValue("V2397(+60)", "(", ")" )
    

提交回复
热议问题