当前位置 : 主页 > 编程语言 > c语言 >

获取其他字符串vb.net之间的字符串

来源:互联网 收集:自由互联 发布时间:2021-06-24
我有下面的代码.如何在括号内输入字符串?谢谢. Dim tmpStr() As String Dim strSplit() As String Dim strReal As String Dim i As Integer strWord = "hello (string1) there how (string2) are you?" strSplit = Split(strWord, "(")
我有下面的代码.如何在括号内输入字符串?谢谢.

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

    strWord = "hello (string1) there how (string2) are you?"

    strSplit = Split(strWord, "(")
    strReal = strSplit(LBound(strSplit))

    For i = 1 To UBound(strSplit)
        tmpStr = Split(strSplit(i), ")")
        strReal = strReal & tmpStr(UBound(tmpStr))
    Next
Dim src As String = "hello (string1) there how (string2) are you?"
Dim strs As New List(Of String)

Dim start As Integer = 0
Dim [end] As Integer = 0

While start < src.Length

    start = src.IndexOf("("c, start)
    If start <> -1 Then
        [end] = src.IndexOf(")"c, start)
        If [end] <> -1 Then
            Dim subStr As String = src.Substring(start + 1, [end] - start - 1)
            If Not subStr.StartsWith("(") Then strs.Add(src.Substring(start + 1, [end] - start - 1))
        End If
    Else
        Exit While
    End If

    start += 1 ' Increment start to skip to next (

End While

这应该做到这一点.

Dim result = Regex.Matches(src, "\(([^()]*)\)").Cast(Of Match)().Select(Function(x) x.Groups(1))

也会有用.

网友评论