19 lines
641 B
C#
19 lines
641 B
C#
namespace EnVisage.Code.Extensions
|
|
{
|
|
public static class StringExtensions
|
|
{
|
|
private const string Continuation = "...";
|
|
public static string Truncate(this string value, int maxLength)
|
|
{
|
|
if (string.IsNullOrEmpty(value)) return value;
|
|
return value.Length <= maxLength ? value : value.Substring(0, maxLength);
|
|
}
|
|
|
|
public static string TruncateWithContinuation(this string value, int maxLength)
|
|
{
|
|
if (string.IsNullOrEmpty(value) || value.Length <= maxLength) return value;
|
|
return value.Truncate(maxLength) + Continuation;
|
|
}
|
|
}
|
|
}
|