Skip to content

Instantly share code, notes, and snippets.

@hbulens
Created January 13, 2018 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hbulens/e07cf65160a206d883eff136cf59fbac to your computer and use it in GitHub Desktop.
Save hbulens/e07cf65160a206d883eff136cf59fbac to your computer and use it in GitHub Desktop.
public static string CharacterLimit(this string text, int length)
{
if (text.Length <= length) return text;
int pos = text.IndexOf(" ", length);
if (pos >= 0) return text.Substring(0, pos) + "...";
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment