Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I've been using @Html.Raw(umbraco.library.RemoveFirstParagraphTag(Model.GetPropertyValue("homeNewsPerspectiveTitle").ToString()))
what's the v8 version of that? umbraco.library.RemoveFirstParagraphTag doesn't seem to exist, or if it does I haven't found it yet.
The whole umbraco.library has been obsolete for years and has now been removed from v8 as a part of the "code cleanup".
Though, the RemoveFirstParagraphTag method was nice and should be requested re-invoked ...
Does anyone have a alternative for the deprecated RemoveFirstParagraphTag? I use that method extensively throughout my projects.
The implementation for it was like so:
public static string RemoveFirstParagraphTag(string text)
if (text.Length > 5)
if (text.ToUpper().Substring(0, 3) == "<P>")
text = text.Substring(3, text.Length - 3);
if (text.ToUpper().Substring(text.Length - 4, 4) == "</P>")
text = text.Substring(0, text.Length - 4);
so you could add an extension method or service to do the same logic in your new projects.
One problem with using this method from Umbraco is that if you have multiple paragraphs or content that follows a paragraph, it will only strip the first opening tag and the last closing tag, which could result in something like the following:
My first paragraph</p> <p>My last paragraph
A paragraph of text</p> <ul><li>A list item</li></ul>
It's usually better to leave the text alone in those cases since we're only interested in removing paragraph tags that Umbraco injected around the content. Here's a better implementation:
public static class StringExtensions
/// Strips out <P> and </P> tags if they were used as a wrapper
/// for other HTML content.
/// <param name="text">The HTML text.</param>
public static string RemoveParagraphWrapperTags(this string text)
string trimmedText = text.Trim();
string upperText = trimmedText.ToUpper();
int paragraphIndex = upperText.IndexOf("<P>");
if (paragraphIndex != 0 ||
paragraphIndex != upperText.LastIndexOf("<P>") ||
upperText.Substring(upperText.Length - 4, 4) != "</P>")
// Paragraph not used as a wrapper element
// Remove paragraph wrapper tags
return trimmedText.Substring(3, trimmedText.Length - 7);
Usage from controller:
string rawContent = content.Value<string>("myContent");
string fixedContent = rawContent.RemoveParagraphWrapperTags();
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted