删除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);更多推荐
发布评论