Created
October 18, 2012 06:26
-
-
Save Larry57/3910170 to your computer and use it in GitHub Desktop.
Truncate a string too long for display. So, "A too long string" become "A too long s..." if limit is 12 chars.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment