truncate static method

String truncate(
  1. String str,
  2. int chars
)

Truncates a string to a certain length and adds '...' if necessary. The length also accounts for the ellipsis, so a maximum length of 10 and a string 'Hello World!' produces 'Hello W...'. @param {string} str The string to truncate. @param {number} chars Max number of characters. @return {string} The truncated {@code str} string.

Implementation

static String truncate(String str, int chars)
{
  return truncateWithCustomEllipsis(str, chars, "...");
}