Monday, February 7, 2011

C# - Truncate String with word boundary



public String Truncate(String content, int length)
{
    if(!String.IsNullOrEmpty(content) && content.Length > length)
      return content.Substring(0, (content.Substring(0, length)).LastIndexOf(" "));
    return content;
}

No comments:

Post a Comment