I have the following function inside my HomeController class:
public class HomeController : Controller
{
public string Strip(string text)
{
return Regex.Replace(text,@"<(.|\n)*?>",string.Empty);
}
On my view I have the following to show an article from a database:
<%= item.story %>
A typical article will look like the following:
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea <em>commodo consequat</em>.</p> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
As you can see the text has HTML tags throughout. What I would like to do is use my Strip function with item.story to remove those HTML tags. After that I would like to truncate the remaining text into 20 WORDS.
So I'll end up with something along the lines of:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua dolore...
with no HTML tags and only about 20 WORDS long.
How do I do this with my current code? Is the HomeController the correct place for the Strip function to be? Thanks