Skip to content

Instantly share code, notes, and snippets.

@romeshniriella
Created November 18, 2020 04:19
Show Gist options
  • Save romeshniriella/034e70d0a1a1f644b8ace356f508eff5 to your computer and use it in GitHub Desktop.
Save romeshniriella/034e70d0a1a1f644b8ace356f508eff5 to your computer and use it in GitHub Desktop.
internal static class StringExtensions
{
public static string TruncateTo(this string val, int maxLength, bool ellipsis = true)
{
if (val == null || val.Length <= maxLength)
{
return val;
}
ellipsis = ellipsis && maxLength >= 3;
return ellipsis ? val.Substring(0, maxLength - 3) + "***" : val.Substring(0, maxLength);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment