I'm looking for a method to remove the start of an anchor tag "<a>" and it's href URL it contains from an Umbraco Property.
E.g. text = blogItem.GetPropertyValue<string>("text");
I want to remove all anchor tags from the string above as I am exporting as a csv file however, there are different anchor tags which contains different href URL content.
I know I can perform
text = blogItem.GetPropertyValue<string>("text").Replace("</a>", "");
to remove the end anchor tags, I'm just unsure how to do it at the start.
@using HtmlAgilityPack
@{
Layout = null;
}
@{
var htmlDoc = new HtmlDocument();
var text = blogItem.GetPropertyValue<string>("text").Replace("</a>", "");
htmlDoc.LoadHtml(text);
var aNodes = htmlDoc.DocumentNode.SelectNodes("//a");
foreach (var node in aNodes)
{
// could check if they are an Umbraco link first here?
node.Remove();
}
text = htmlDoc.DocumentNode.OuterHtml;
}
<textarea>@text</textarea>
Removing opening anchor tag content
Hi,
I'm looking for a method to remove the start of an anchor tag "
<a>
" and it's href URL it contains from an Umbraco Property.E.g.
text = blogItem.GetPropertyValue<string>("text");
I want to remove all anchor tags from the string above as I am exporting as a csv file however, there are different anchor tags which contains different href URL content.
I know I can perform
to remove the end anchor tags, I'm just unsure how to do it at the start.
Any suggestions would be greatly appreciated.
Thanks
sounds like you probably need to use regex, could you give a few example anchor tags and what you want the outcome to be.
Hi,
I would use HtmlAgilityPack (install via Nuget).
is working on a reply...