Skip to content

Instantly share code, notes, and snippets.

@morbidcamel101
Created August 18, 2015 02:20
Show Gist options
  • Select an option

  • Save morbidcamel101/0ebdc9763765912d4002 to your computer and use it in GitHub Desktop.

Select an option

Save morbidcamel101/0ebdc9763765912d4002 to your computer and use it in GitHub Desktop.
// C# version
public static string AutoElipsis(this string text, int maxLength)
{
if (text == null || text.Length < maxLength)
return text;
return text.Substring(0, maxLength-3) + "...";
}
// JS version
if (!String.prototype.autoElipsis) {
String.prototype.autoElipsis = function(maxLength) {
if (this == null || this.length < maxLength)
return this;
return this.substring(0, maxLength-3) + "...";
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment