get string between other string vb.net

前端 未结 4 1727
小鲜肉
小鲜肉 2021-01-19 15:32

I have code below. How do I get strings inside brackets? Thank you.

Dim tmpStr() As String
    Dim strSplit() As String
    Dim strReal As String
    Dim i A         


        
4条回答
  •  执笔经年
    2021-01-19 16:11

    This is what regular expressions are for. Learn them, love them:

    ' Imports System.Text.RegularExpressions
    Dim matches = Regex.Matches(input, "\(([^)]*)\)").Cast(of Match)()
    Dim result = matches.Select(Function (x) x.Groups(1))
    

    Two lines of code instead of more than 10.

    In the words of Stephan Lavavej: “Even intricate regular expressions are easier to understand and modify than equivalent code.”

提交回复
热议问题