I'm trying to limit the number of characters in a string.
However when I try the following:
Truncate.TruncateString(_longString, 300);
I Still get spaces included beyond 300 characters. Is there an alternative so that spaces are counted within the character limit?
public static string TruncateString (this string value, int maxChars)
{
return value.Length <= maxChars ? value : value.SubString(0, maxChars) + "...";
}
Truncateclass is not part of the .NET framework. I'd recommend talking to whoever wrote theTruncateStringmethod.value.SubString(0, maxChars) + "..."will end with spaces? And how can it be longer thanmaxChars + 3characters?Truncatefor a string. (Example) This one fails if the string has more than 300 chars in length because the string returned is 303 chars