Return to Snippet

Revision: 47577
at June 10, 2011 06:01 by stuartleitch


Initial Code
namespace System
{
    public static class StringTruncator
    {
        /// <summary>
        ///   Trims and truncates to specified length if required.
        /// </summary>
        public static string Truncate(this string item, int length)
        {
            return item.Trim().Substring(0, Math.Min(item.Trim().Length, length));
        }
    }
}

Initial URL


Initial Description


Initial Title
StringTruncator

Initial Tags
c#

Initial Language
C#