A simple ASP.Net MVC HTML Helper to truncate a string at an arbitrary length

public static MvcHtmlString DisplayNewsSearchSummary(this HtmlHelper htmlHelper, string input, int requiredLength, string ending = "...")
    // Validate and sanity check first...

   var requiredtext = input.Substring(0, requiredLength - 1);

   var ouputtext = string.Concat(requiredtext.Substring(0, requiredtext.LastIndexOf(' ')), ending);

   return new MvcHtmlString(descriptionText);

Leave a Reply

Your email address will not be published. Required fields are marked *