Created
November 18, 2020 04:19
-
-
Save romeshniriella/034e70d0a1a1f644b8ace356f508eff5 to your computer and use it in GitHub Desktop.
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
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