Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC C# How to use this function
    text
    copied!<p>I have the following function inside my HomeController class:</p> <pre><code>public class HomeController : Controller { public string Strip(string text) { return Regex.Replace(text,@"&lt;(.|\n)*?&gt;",string.Empty); } </code></pre> <p>On my view I have the following to show an article from a database:</p> <pre><code>&lt;%= item.story %&gt; </code></pre> <p>A typical article will look like the following:</p> <pre><code>&lt;p&gt;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 &lt;em&gt;commodo consequat&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.&lt;/p&gt; </code></pre> <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 <strong>20 WORDS</strong>.</p> <p>So I'll end up with something along the lines of:</p> <p><code>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua dolore...</code> with no HTML tags and only about <strong>20 WORDS long</strong>.</p> <p>How do I do this with my current code? Is the HomeController the correct place for the Strip function to be? Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload