vb.net:拆分字符串 [英] vb.net : split string

查看:41
本文介绍了vb.net:拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含如下内容的字符串:

i have a string which contains something like this:

你好,这是一个{test, example}

你好,这是一个{test, example}一些其他文本

你好,这是一个 {test, example} 其他一些文本 { test1, example1 } 等等等等

这就是我想要的:

创建一个包含所有普通文本和 {} 之间的所有文本的列表

create a list with all the normal text and all the text between the {}

例如:

  • 你好,这是一个
  • 测试,示例

  • 你好,这是一个
  • 测试、示例
  • 其他一些文字

等等(就像字符串的第一个例子一样.

and so on ( just like the first examples of how the string looks like.

我怎样才能做到最好?

推荐答案

试试这个,它使用 RegEx 而不是 Split 函数 -

Try this, it uses a RegEx instead of the Split function -

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 列表现在应该包含所需的列表.

The words list should now contain the required list.

这篇关于vb.net:拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆