将字符串拆分为多个部分

Split a string into parts

我正在尝试将字符串拆分成多个部分,但无法弄清楚!

我的主要观点来自一个字符串

"hello bye see you" 

阅读自"bye" to "you"

我试过了

 Dim qnew() As String = tnew.Split(" ")

但是我在代码的其他部分遇到了困难,我真的很想得到一些帮助。 对不起,如果我不是最擅长解释事情的人,至少我尽力了:/

我假设您的预期输出是 bye see you。如果我理解正确,那么可以使用以下 方法 来获得所需的输出:

在此字符串中拆分为一个数组(splits()),分隔符为" ",并找到bye (j)和you(k) 在数组中,然后使用 for loop 获取数组中 byeyou 之间的字符串。

Function GETSTRINGBETWEEN(ByVal start As String, ByVal parent As String, ByVal [end] As String)
        Dim output As String = ""
        Dim splits() As String = parent.Split(" ")
        Dim i As Integer
        Dim j As Integer = Array.IndexOf(splits, start)
        Dim k As Integer = Array.IndexOf(splits, [end])
        For i = j To k
            If output = String.Empty Then
                output = splits(i)
            Else
                output = output & " " & splits(i)
            End If
        Next
        Return output
    End Function

用法:

Dim val As String
val = GETSTRINGBETWEEN("bye", "hello bye see you", "you")
'val="bye see you"

Function GET_STRING_BETWEEN(ByVal start As String, ByVal parent As String, ByVal [end] As String)
        Dim output As String
        output = parent.Substring(parent.IndexOf(start) _
                                                , (parent.IndexOf([end]) _
                                                   - parent.IndexOf(start)) _
                                                   ).Replace(start, "").Replace([end], "")
        output = start & output & [end]
        Return output
    End Function

用法:

Dim val As String
val = GET_STRING_BETWEEN("bye", "hello bye see you", "you")
'val="bye see you"