Skip to content

Instantly share code, notes, and snippets.

@iamphill
Last active December 23, 2015 06:29
Show Gist options
  • Save iamphill/6594500 to your computer and use it in GitHub Desktop.
Save iamphill/6594500 to your computer and use it in GitHub Desktop.
Create a snippet of text with the specified length
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