Skip to main content
added 175 characters in body
Source Link
InCode
  • 503
  • 3
  • 10
  • 25

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) + "...";
}

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?

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) + "...";
}
Source Link
InCode
  • 503
  • 3
  • 10
  • 25

How to Truncate String within Limited Characters including space

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?