2011-10-22 94 views
0

我有含有像这样的字符串:vb.net:分割字符串

你好,这是一{测试,例如}

你好,这是一{测试,例如}一些其他文本

你好,这是一{测试,例如}某些其他文本{TEST1,例1}等等等等等等

现在是这样的,我想什么:

创建一个列表与所有的普通文本和所有的{}

所以例如之间的文本:

  • 您好,这是一个
  • 测试,例如

  • 您好,这是一个
  • 测试,例如
  • 一些其他文本

等(就像串看起来像第一个例子。

我该如何做到最好?

+0

你想要在两个单独的列表中的'}'之间的所有正常文本和所有文本? – ipr101

+0

不,他们必须在同一个名单上。 – Ruben

回答

0

试试这个,它使用正则表达式,而不是Split功能 -

Dim value As String = "hello this is an {test, example} some other text { test1, example1 } etc etc etc" 
Dim words As List(Of String) = new List(Of String) 

' Get a collection of matches. 
Dim matches As MatchCollection = Regex.Matches(value, "[^\{\}]+") 

For Each match As Match In matches 
    words.Add(match.Captures(0).Value.Trim) 
Next 

words名单现在应该包含所需的列表。

+0

非常感谢:D – Ruben