Truncate the given string to a certain number of characters.

 @param [String] string
   the string to truncate
 @param [Hash] options
   the list of options (such as +length+)
174022
def truncate(string, options = {})
      length = options[:length] || 30

      if string.length > length
        string[0..length - 3] + "..."
      else
        string
      end
    end
205540
def truncate(message, limit=500):
    
    if len(message) > limit:
        trc_msg = ''.join([message[:limit // 2 - 2],
                           ' .. ',
                           message[len(message) - limit // 2 + 2:]])
    else:
        trc_msg = message
    return trc_msg
183536
def trunc_str(s: str) -> str:
    """"""
    if len(s) > max_str_size:
        i = max(0, (max_str_size - 3) // 2)
        j = max(0, max_str_size - 3 - i)
        s = s[:i] + "..." + s[-j:]
    return s
540207
public static function truncate($value, array $params)
    {
        if (empty($params['length']) || !is_numeric($params['length'])) {
            $params['length'] = 4;
        }

        return StringHelper::truncate($value, (int)$params['length']);
    }
580504
public static String truncate (String str, int limit, String appendage)
    {
        if (str == null || str.length() <= limit) {
            return str;
        }
        return str.substring(0, limit - appendage.length()) + appendage;
    }
161979
public static String truncate(int n, int smallestDigit, int biggestDigit) {
    int numDigits = biggestDigit - smallestDigit + 1;
    char[] result = new char[numDigits];
    for (int j = 1; j < smallestDigit; j++) {
      n = n / 10;
    }
    for (int j = numDigits - 1; j >= 0; j--) {
      result[j] = Character.forDigit(n % 10, 10);
      n = n / 10;
    }
    return new String(result);
  }
1318770
def separator(string = "")
      if separators[options.size]
        separators[-1] += "\n#{string}"
      else
        separators[options.size] = string
      end
    end
1234879
function truncateString(str, block_size) {
    block_size = block_size || 350;

    var blocks = [],
        current_pos;

    for (current_pos = 0; current_pos < str.length; current_pos = current_pos + block_size) {
        blocks.push(str.substr(current_pos, block_size));
    }

    return blocks;
}
1336513
def truncate_between(str, after = 30)
      str = '' if str.nil?
      str.length > after ? "#{str[0..(after / 2) - 2]}...#{str[(str.length - ((after / 2) - 2))..str.length]}" : str
    end
1079274
def encode_string_with_trailing_spaces(string, target_length)
      length = string.length
      if length < target_length
        return "#{[string].pack(@str)}#{['20'*(target_length-length)].pack(@hex)}"
      elsif length == target_length
        return [string].pack(@str)
      else
        raise "The specified string is longer than the allowed maximum length (String: #{string}, Target length: #{target_length})."
      end
    end
895756
function truncateString(str, max) {

  str = str != null ? str : ''
  str = String(str)

  if(max == Infinity) return str

  var i = 0
  var wwidth = 0
  while (i < str.length) {
    var w = wcwidth(str.charAt(i))
    if(w + wwidth > max)
      break
    wwidth += w
    ++i
  }
  return str.slice(0, i)
}
124645
protected function truncate($string, $length = 30, $separator = '...')
    {
        if (mb_strlen($string) > $length) {

            return rtrim(mb_substr($string, 0, $length)) . $separator;
        }

        return $string;
    }
113025
function truncate(arr, len) {
    if (arr.length > len) {
      arr.length = len;
      return true;
    }
  }
367673
def trim! desired_row_length=nil
      max_length = self.collect{|a| a.trim.length }.max
      self_count = self.count-1
      self.count.times do |index|
        index = self_count - index
        if self[index].trim.empty?
          self.delete_at(index)
        else
          break
        end
      end
      self.each{|a| a.trim!(max_length)}
      self
    end
987570
def truncate(string, length, ellipsis="…"):
    
    if len(string) > length:
        return string[: length - len(ellipsis)] + ellipsis
    return string
511142
function endsWith(longStr, shortStr) {
		var longLen = longStr.length, shortLen = shortStr.length;
		return (longLen >= shortLen) &&
			(longStr.substr(longLen - shortLen) === shortStr);
	}
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