删除html标记并在c#中找到结束标记时将其拆分(Remove html tags and split it when end tag was found in c#)

编程入门 行业动态 更新时间:2024-10-26 04:20:29
删除html标记并在c#中找到结束标记时将其拆分(Remove html tags and split it when end tag was found in c#)

我想从以下字符串中删除所有html标记并将其拆分而不使用句点(句号)作为匹配字符。 以下sting是动态的,可以在list标签内有更多条件

<li>This Offer cannot be redeemed with any other offer.</li><li>Only one Offer can be used at a time.</li><li>This Offer is not transferable.</li><li>......</li><li>....</li</ul></div>

我期待以下的感受

此优惠不可兑换任何其他优惠。 一次只能使用一个优惠。 此优惠不可转让。 .... ....

I want to remove all html tags from the following string and split it without using the period(full stop) as matching character. The following sting is dynamic one which can have more conditions inside list tag

<li>This Offer cannot be redeemed with any other offer.</li><li>Only one Offer can be used at a time.</li><li>This Offer is not transferable.</li><li>......</li><li>....</li</ul></div>

I'm Expecting the following relult

This Offer cannot be redeemed with any other offer. Only one Offer can be used at a time. This Offer is not transferable. .... ....

最满意答案

String[] myString = yourString.replace("<li>", "").Split(new string[] { "</li>" }, StringSplitOptions.RemoveEmptyEntries);

尝试这个

const string HTML_TAG_PATTERN = "<[^/li]>"; // may require some change string safeString = Regex.Replace(yourString, HTML_TAG_PATTERN, string.Empty); String[] myString = safeString.Split(new string[] { "</li>" }, StringSplitOptions.RemoveEmptyEntries);

你也可以试试这个正则表达式

string acceptable = "li"; string stringPattern = @"</?(?(?=" + acceptable + @")notag|[a-zA-Z0-9]+)(?:\s[a-zA-Z0-9\-]+=?(?:(["",']?).*?\1?)?)*\s*/?>"; string yourString= Regex.Replace(yourString, stringPattern, string.Empty); String[] myString = yourString.replace("<li>", "").Split(new string[] { "</li>" }, StringSplitOptions.RemoveEmptyEntries); String[] myString = yourString.replace("<li>", "").Split(new string[] { "</li>" }, StringSplitOptions.RemoveEmptyEntries);

try this

const string HTML_TAG_PATTERN = "<[^/li]>"; // may require some change string safeString = Regex.Replace(yourString, HTML_TAG_PATTERN, string.Empty); String[] myString = safeString.Split(new string[] { "</li>" }, StringSplitOptions.RemoveEmptyEntries);

you can try this regex too

string acceptable = "li"; string stringPattern = @"</?(?(?=" + acceptable + @")notag|[a-zA-Z0-9]+)(?:\s[a-zA-Z0-9\-]+=?(?:(["",']?).*?\1?)?)*\s*/?>"; string yourString= Regex.Replace(yourString, stringPattern, string.Empty); String[] myString = yourString.replace("<li>", "").Split(new string[] { "</li>" }, StringSplitOptions.RemoveEmptyEntries);

更多推荐

本文发布于:2023-07-21 09:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1208979.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标记   并在   时将   结束   中找到

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!