Limit the characters of td tag in html table
I am using asp.net mvc for my application. I use html table to list all the Roles from Roles table. I have a html table which shows details of roles. The table has RoleDescription which can grow to many characters. I need to limit the characters shown in the td to 25 characters for the RoleDesscription in the tds of the html table. How can i achieve this? 开发者_运维知识库
public static string Truncate(this string input, int maxLength)
{
if (input.Length > maxLength)
{
input = input.Substring(0, maxLength - 3) + "...";
}
return input;
}
Razor usage
<td>@Model.RoleDescription.Truncate(25)</td>
WebForms usage
<td><%= Model.RoleDescription.Truncate(25) %></td>
if( someString.Length > 25 )
someString = someString.SubString( 0, 25 )
精彩评论