Last active
December 23, 2015 06:29
-
-
Save iamphill/6594500 to your computer and use it in GitHub Desktop.
Create a snippet of text with the specified length
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 CreateSnippet(string s, int length) | |
{ | |
if (String.IsNullOrEmpty(s)) | |
{ | |
return ""; | |
} | |
const string Ellipsis = "..."; | |
if (s.Length > length) | |
{ | |
return s.Substring(0, length - Ellipsis.Length) + Ellipsis; | |
} | |
else | |
{ | |
return s; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment