(this string value, int maxLength, string suffix = "...")
| 3 | public static class StringExtensions |
| 4 | { |
| 5 | public static string Truncate(this string value, int maxLength, string suffix = "...") |
| 6 | { |
| 7 | if (string.IsNullOrEmpty(value)) |
| 8 | return value; |
| 9 | |
| 10 | if (value.Length <= maxLength) |
| 11 | return value; |
| 12 | |
| 13 | return $"{value[..(maxLength - suffix.Length)]}{suffix}"; |
| 14 | } |
| 15 | } |