.net 查找子字符串的所有匹配项,并将其从点a复制到点b,然后复制到列表中

.net 查找子字符串的所有匹配项,并将其从点a复制到点b,然后复制到列表中,.net,vb.net,string,.net,Vb.net,String,我将尝试用伪代码编写此代码,但我自己正在努力编写vb.net代码,因为我对该语言相当陌生 我想在字符串中找到点a并复制所有字符,直到点b结束 但是,原始字符串包含我想要的“句子”的多次出现,因此我希望获得列表中的所有出现 Dim original ="hello mike bye some words hello kate your nice bye" etc. Dim list As New List(Of String) Dim pointA As String ="hello" Dim

我将尝试用伪代码编写此代码,但我自己正在努力编写vb.net代码,因为我对该语言相当陌生

我想在字符串中找到点a并复制所有字符,直到点b结束

但是,原始字符串包含我想要的“句子”的多次出现,因此我希望获得列表中的所有出现

Dim original ="hello mike bye some words hello kate your nice bye" etc.

Dim list As New List(Of String)
Dim pointA As String ="hello"
Dim pointB As String = "bye"

*Psuedo Code*
While not end of string
dim copy As String
--Find first a
--Find first b
--copy all sentence
--list.Add(copy)
--Find next occurrence

essentially the List would now contain:
list(0) = "hello mike bye"
list(1) = "hello kate your nice bye"

感谢您的时间和努力。

使用字符串方法IndexOf和Substring

Dim original ="hello mike bye some words hello kate your nice bye and other strings"
Dim startWord = "hello"
Dim stopWord = "bye"
Dim words = new List(Of String)()

Dim pos1 = original.IndexOf(startWord, StringComparison.CurrentCultureIgnoreCase)
Dim pos2 = original.IndexOf(stopWord, StringComparison.CurrentCultureIgnoreCase)
while pos1 <> -1 AndAlso pos2 <> -1
    words.Add(original.Substring(pos1, pos2 + stopWord.Length - pos1))
    pos1 = original.IndexOf(startWord, pos1 + 1, StringComparison.CurrentCultureIgnoreCase)
    pos2 = original.IndexOf(stopWord, pos2 + 1, StringComparison.CurrentCultureIgnoreCase)
End While

for each s in words
    Console.WriteLine("[" + s + "]")
next
Dim original=“你好,迈克,再见一些词你好,凯特,再见,还有其他字符串”
Dim startWord=“你好”
Dim stopWord=“再见”
Dim words=新列表(字符串)()
Dim pos1=original.IndexOf(startWord,StringComparison.CurrentCultureIgnoreCase)
Dim pos2=original.IndexOf(stopWord、StringComparison.CurrentCultureIgnoreCase)
而pos1-1和pos2-1
添加(原始的子字符串(pos1,pos2+stopWord.Length-pos1))
pos1=original.IndexOf(startWord,pos1+1,StringComparison.CurrentCultureIgnoreCase)
pos2=original.IndexOf(stopWord,pos2+1,StringComparison.CurrentCultureIgnoreCase)
结束时
每一个都是用文字表达的
Console.WriteLine(“[”+s+“]))
下一个

Thank这在测试用例中非常有效,但是我刚刚注意到原始字符串不包含空格。例如。。。。Dim original=“hellomikebyesomewordshellokateyournicebyeandother strings”是否仍然可以在此中找到子字符串?是否尝试过?有或没有空格都没有问题