Return to Snippet

Revision: 55830
at February 23, 2012 18:56 by ctrlbr34k


Initial Code
public static string Truncate(this string myString, int limit, string symbol)
{
    if (myString == null)
        return null;
 
    if (limit < 0)
        throw new ArgumentOutOfRangeException("limit", limit, "must be 0 or greater");
 
    if (symbol == null)
        throw new ArgumentNullException("symbol must not be null");
 
    if (myString.Length < limit)
        return myString;
 
    return myString.Substring(0, limit) + symbol;
}

Initial URL

                                

Initial Description
Truncate("This is way too long", 11, "...") returns "This is way..."

Initial Title
Truncate Text for display

Initial Tags

                                

Initial Language
C#