c# - 如何将带有 HTML 标签的文本拆分为数组

标签 c# windows-phone-8.1 windows-8.1 win-universal-app

我有非常简单的 HTML 文本(只有 <b> 标签)例如

Lorem Ipsum is <b>simply dummy</b> text of the printing and <b>typesetting industry</b>

我想像这样将文本拆分为数组:

[0] - Lorem Ipsum is 
[1] - <b>simply dummy</b>
[2] - text of the printing and
[3] - <b>typesetting industry</b>

HTML 标签内的文本必须与其他文本分开。有什么简单的解决方法吗?

谢谢

最佳答案

您可以使用以下代码实现此目的

string value = @"Lorem Ipsum is <b>simply dummy</b> text of the printing and <b>typesetting industry</b>";
var parts = Regex.Split(value, @"(<b>[\s\S]+?<\/b>)").Where(l => l != string.Empty).ToArray();

关于c# - 如何将带有 HTML 标签的文本拆分为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30455489/

相关文章:

c# - 通用应用程序缺少 WriteableBitmap SaveJpeg

c# - 不要逃避换行

c# - 使用 Entity Framework 和存储过程进行并发检查

c# - 经过身份验证的调用

c# - FilePicker 在画廊中不断崩溃(WP 8.1 RT)

windows-8.1 - Windows 启动 - 如何从批处理文件以管理员身份运行程序

c# - 在 Windows 应用商店应用程序的文本框焦点事件上弹出屏幕键盘

c# - 我如何从 C++ 应用程序调用 http 处理程序?

c# - 即使正确键入了 xmlns,也无法在 XAML 中引用 ValueConverter 类

c++ - 在 C++/CX 中绑定(bind) IValueConverter 类时出错