Truncate text to specified length.
@param {string} str Text to be truncated.
@param {number} len Length to which text should be truncated
@return {?string} Returns truncated text only if it was changed
761054
function truncate(str, len) {
        // Truncate text to specified length
        if (str.length > len) {
            str = str.substr(0, len);

            // To prevent awkwardly truncating in the middle of a word,
            // attempt to truncate at the end of the last whole word
            var lastSpaceChar = str.lastIndexOf(" ");
            if (lastSpaceChar < len && lastSpaceChar > -1) {
                str = str.substr(0, lastSpaceChar);
            }
            return str;
        }
    }
972343
function PrependLength(buffer, len) {
  let lenBuf = new Buffer(4);
  lenBuf.writeUInt32LE(len, 0);
  return Buffer.concat([lenBuf, buffer], buffer.length + 4);
}
863558
def truncate(s: str, length: int = DEFAULT_CURTAIL) -> str:
    
    if len(s) > length:
        s = s[: length - 1] + '…'
    return s
685034
def truncate(string, width, options={})
      trailing = options[:trailing] || '…'

      chars = string.to_s.chars.to_a
      if chars.length < width && chars.length > 3
        chars.join
      elsif chars.length > 3
        (chars[0, width - trailing.length].join) + trailing
      end
    end
924361
public static function truncateValue($string, $limit, $endchars = '...')
    {

        if (!is_array($string) && !is_object($string)) {
            $stringLength = strlen($string);
            $endcharsLength = strlen($endchars);

            if ($stringLength > (int) $limit) {
                $cut = (int) ($limit - $endcharsLength);
                $string = substr($string, 0, $cut) . $endchars;
            }
        }
        return $string;
    }
1369324
public static String wrap(String str, int wrapTextLength) {
	if (wrapTextLength <= 0) return str;

	StringBuilder rtn = new StringBuilder();
	String ls = SystemUtil.getOSSpecificLineSeparator();
	Array arr = ListUtil.listToArray(str, ls);
	int len = arr.size();

	for (int i = 1; i <= len; i++) {
	    rtn.append(wrapLine(Caster.toString(arr.get(i, ""), ""), wrapTextLength));
	    if (i + 1 < len) rtn.append(ls);
	}
	return rtn.toString();
    }
556696
public static function java_truncate(string $str): string
    {
        if (strlen($str) > 955) {
            return substr($str, 0, 475).'[...]'.substr($str, -475);
        }

        return $str;
    }
1265848
public static function truncate2(string $str, int $start, int $length = null): string
    {
        if (!$length) {
            $length = $start;
            $start  = 0;
        }

        if (\strlen($str) <= $length) {
            return $str;
        }

        if (\function_exists('mb_substr')) {
            $str = \mb_substr(\strip_tags($str), $start, $length, 'utf-8');
        } else {
            $str = \substr($str, $start, $length) . '...';
        }

        return $str;
    }
952049
def truncate_ellipsis(line, length=30):
    """"""

    l = len(line)
    return line if l < length else line[:length - 3] + "..."
633682
def truncate(string, index):
    """"""
    if len(string) > index and index > 0:
        string = string[:index - 1] + u('…')
    return string
247628
function truncate(el) {
    if (!el) {
        return;
    }

    const text = el.textContent;

    if (this.isTextOverflowing(el)) {
        const checkFunc = i => {
            el.textContent = text.substring(0, i);
            return this.isTextOverflowing(el) ? -1 : 0;
        };
        const len = binarySearch(text.length - 1, checkFunc);
        const truncatedText = text.substring(0, len).slice(0, -2);
        el.innerHTML = `<span aria-hidden="true">${truncatedText}…</span><span class="clipped">${text}</span>`;
    }
}
77359
function stringTrim (str) {
  return str && str.trim ? str.trim() : stringTrimRight(stringTrimLeft(str))
}
953957
function (str) {
      str = str.trim();
      let space = str.indexOf(' ');
      if (space === -1) {
        return str.length ? [str] : [];
      } else {
        return [str.substring(0, space).trim(), str.substring(space + 1).trim()];
      }
    }
1122890
private function truncate_skip( &$ret, $text, $search, $start, $len = null ) {
		if ( $len === null ) {
			$len = -1; // -1 means "no limit" for strcspn
		} elseif ( $len < 0 ) {
			$len = 0; // sanity
		}
		$skipCount = 0;
		if ( $start < strlen( $text ) ) {
			$skipCount = strcspn( $text, $search, $start, $len );
			$ret .= substr( $text, $start, $skipCount );
		}
		return $skipCount;
	}
826774
def truncate(input, length = 50, truncate_string = "...".freeze)
      return if input.nil?
      input_str = input.to_s
      length = Utils.to_integer(length)
      truncate_string_str = truncate_string.to_s
      l = length - truncate_string_str.length
      l = 0 if l < 0
      input_str.length > length ? input_str[0...l] + truncate_string_str : input_str
    end
1261081
public static function truncate($str, $length, $trailing='...') {
		$length -= mb_strlen($trailing);

		if (mb_strlen($str) > $length)
			return mb_substr($str,0,$length).$trailing;
		return $str;
	}
746704
def cut_to_length(text, length, delim):
    
    cut = text.find(delim, length)
    if cut > -1:
        return text[:cut]
    else:
        return text