How can I get the characters between 2 other characters?

后端 未结 6 739
醉梦人生
醉梦人生 2020-12-20 15:57

I have a string which at some point contains the set of characters in the following format [123].

What I would like to do is get the characters between

相关标签:
6条回答
  • 2020-12-20 16:30

    My solution:

    Dim s As String = "nav[1]=root"
    dim result as String = s.substring(s.indexof("[")+1, s.indexof("]")-s.indexof("[")-1)
    
    0 讨论(0)
  • 2020-12-20 16:30

    You could do something like this..

    Dim val As String = str.Substring(1, str.Length - 2) // replace str with your string variable
    
    0 讨论(0)
  • 2020-12-20 16:32
    Dim s As String = "foo [123]=ro bar"
    Dim i As Integer = s.IndexOf("[")
    Dim f As String = s.Substring(i + 1, s.IndexOf("]", i + 1) - i - 1)
    
    0 讨论(0)
  • 2020-12-20 16:44

    the statement RegularExpressions.Regex("\[([^\]]*)\]") will returns the value inside bracket And the bracket its self!

    I have used this statement to return the IPAddress surrounded by () inside long string:-

    Dim IPRegEx As Regex = New Regex("(?<=\().*?(?=\))")
    
    0 讨论(0)
  • 2020-12-20 16:47

    You could use regular expression.

        Dim s, result As String
        Dim r As RegularExpressions.Regex
    
        s = "aaa[bbbb]ccc"
        r = New RegularExpressions.Regex("\[([^\]]*)\]")
    
        If r.IsMatch(s) Then
            result = r.Match(s).Value
        Else
            result = ""
        End If
    
    0 讨论(0)
  • 2020-12-20 16:52
    Dim s As String = "nav[1]=root"
    dim result as String = s.Substring(s.IndexOf("[") + 1, s.IndexOf("]", s.IndexOf("[")) - s.IndexOf("[") - 1)
    
    0 讨论(0)
提交回复
热议问题