如何将带有 HTML 标签的文本拆分为数组 [英] How to split text with HTML tags to array

查看:19
本文介绍了如何将带有 HTML 标签的文本拆分为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have very simple text with HTML (only <b> tag) e.g.

Lorem Ipsum 是 只是虚拟的;文字印刷<b>排版行业</b>

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

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

I would like to split the text to array like this:

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

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

The text inside HTML tag must be separated from another text. Is there any simple solution for it?

谢谢

推荐答案

您可以使用以下代码来实现

You may achieve this using following code

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();

这篇关于如何将带有 HTML 标签的文本拆分为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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