-4

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

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

"hello bye see you" 

读自"bye" to "you"

我试过了

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

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

4

1 回答 1

1

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

在这个字符串中拆分为一个splits()带有分隔符的数组()," "并在数组中找到byej)和youk)的索引,然后使用 afor loop来获取数组中和之间的bye字符串you

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"
于 2015-10-19T06:10:25.660 回答