make limited length string in form:
      "the string is very lo...(and 15 more)"
163015
def shorten_string(string, max_width):
    ''' 
    '''
    string_len = len(string)
    if string_len <= max_width:
        return string
    visible = max_width - 16 - int(log10(string_len))
    # expected suffix len "...(and XXXXX more)"
    if not isinstance(string, unistr):
        visstring = unistr(string[:visible], errors='ignore')
    else:
        visstring = string[:visible]
    return u''.join((visstring, u'...(and ',
                     unistr(string_len - visible), u' more)'))
1230205
function lpad(str, width) {
    str = String(str);
    var n = width - str.length;
    if (n < 1) return str;
    while (n--) str = ' ' + str;
    return str;
}
460799
def limit_chars(function, *args, **kwargs):
    """"""
    output_chars_limit = args[0].reddit_session.config.output_chars_limit
    output_string = function(*args, **kwargs)
    if -1 < output_chars_limit < len(output_string):
        output_string = output_string[:output_chars_limit - 3] + '...'
    return output_string
124960
def _restriction_string(self):
        

        if self.has_minimum:
            string = 'at least '
            value = self._minimum
        elif self.has_maximum:
            string = 'at most '
            value = self._maximum
        elif self.has_exact:
            string = ''
            value = self._exact

        return (string + '{} {}').format(
            value,
            pluralize('time', value)
        )
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
669894
function stringPadEnd (str, targetLength, padString, UNDEFINED) {
  var rest = '' + str
  targetLength = targetLength >> 0
  padString = padString === UNDEFINED ? ' ' : '' + padString
  if (rest.padEnd) {
    return rest.padEnd(targetLength, padString)
  }
  if (targetLength > rest.length) {
    targetLength -= rest.length
    if (targetLength > padString.length) {
      padString += stringRepeat(padString, targetLength / padString.length)
    }
    return rest + padString.slice(0, targetLength)
  }
  return rest
}
1053002
def truncate(data, l=20):
    ""
    info = (data[:l] + '..') if len(data) > l else data
    return info
521382
function short(str, max)
			{
				if (str.length > max)
				{
					str = str.substring(0, Math.round(max / 2)) + '...' +
						str.substring(str.length - Math.round(max / 4));
				}
				
				return str;
			}
420812
def generate_string(out_dir, limits):
    """"""
    max_limit = max((int(v) for v in limits))

    with open(filename(out_dir, 'string'), 'wb') as out_f:
        with IncludeGuard(out_f):
            out_f.write(
                '\n'
                '#include <boost/metaparse/v{0}/cpp11/impl/concat.hpp>\n'
                '#include <boost/preprocessor/cat.hpp>\n'
                .format(VERSION)
            )

            generate_make_string(out_f, 512)

            out_f.write(
                '\n'
                '#ifndef BOOST_METAPARSE_LIMIT_STRING_SIZE\n'
                '#  error BOOST_METAPARSE_LIMIT_STRING_SIZE not defined\n'
                '#endif\n'
                '\n'
                '#if BOOST_METAPARSE_LIMIT_STRING_SIZE > {0}\n'
                '#  error BOOST_METAPARSE_LIMIT_STRING_SIZE is greater than'
                ' {0}. To increase the limit run tools/string_headers.py of'
                ' Boost.Metaparse against your Boost headers.\n'
                '#endif\n'
                '\n'
                .format(max_limit)
            )

            define_macro(out_f, (
                'STRING',
                ['s'],
                '{0}::make_string< '
                '{0}::take(sizeof(s)-1), sizeof(s)-1-{0}::take(sizeof(s)-1),'
                'BOOST_PP_CAT({1}, BOOST_METAPARSE_LIMIT_STRING_SIZE)(s)'
                '>::type'
                .format(
                    '::boost::metaparse::v{0}::impl'.format(VERSION),
                    macro_name('I')
                )
            ))

            out_f.write('\n')
            for limit in xrange(0, max_limit + 1):
                out_f.write(
                    '#define {0} {1}\n'
                    .format(
                        macro_name('I{0}'.format(limit)),
                        macro_name('INDEX_STR{0}'.format(
                            min(int(l) for l in limits if int(l) >= limit)
                        ))
                    )
                )
            out_f.write('\n')

            prev_macro = None
            prev_limit = 0
            for length_limit in (int(l) for l in limits):
                this_macro = macro_name('INDEX_STR{0}'.format(length_limit))
                out_f.write(
                    '#define {0}(s) {1}{2}\n'
                    .format(
                        this_macro,
                        '{0}(s),'.format(prev_macro) if prev_macro else '',
                        ','.join(
                            '{0}((s), {1})'
                            .format(macro_name('STRING_AT'), i)
                            for i in xrange(prev_limit, length_limit)
                        )
                    )
                )
                prev_macro = this_macro
                prev_limit = length_limit
1024998
public String randomString(String permitted, int length) {
        StringBuilder result = new StringBuilder(length);
        int maxIndex = permitted.length();
        for (int i = 0; i < length; i++) {
            int index = random(maxIndex);
            char value = permitted.charAt(index);
            result.append(value);
        }
        return result.toString();
    }
1144684
def _lengstr(obj):
    '''
    '''
    n = leng(obj)
    if n is None:  # no len
       r = ''
    elif n > _len(obj):  # extended
       r = ' leng %d!' % n
    else:
       r = ' leng %d' % n
    return r
1095279
function pad(str) {
  if (str.length < max) {
    return str + ' '.repeat(max - str.length);
  }
  return str;
}
1333730
function string (str, index){
    var str = String(typeof str == 'object' && str.text ? str.text : str)
      , length = utils.strlen(str)
      , width = colWidths[index]
          - (style['padding-left'] || 0)
          - (style['padding-right'] || 0)
      , align = options.colAligns[index] || 'left';

    return repeat(' ', style['padding-left'] || 0)
         + (length == width ? str :
             (length < width
              ? pad(str, ( width + (str.length - length) ), ' ', align == 'left' ? 'right' :
                  (align == 'middle' ? 'both' : 'left'))
              : (truncater ? truncate(str, width, truncater) : str))
           )
         + repeat(' ', style['padding-right'] || 0);
  }
216536
public static String truncate(String string, int maxBytesLength,
            String appendString) {
        return string.getBytes().length > maxBytesLength ? truncate(string,
                maxBytesLength - appendString.getBytes().length) + appendString
                : string;
    }
432687
def shorten(string, maxlen):
    """"""
    if 1 < maxlen < len(string):
        string = string[:maxlen - 1] + u'…'
    return string[:maxlen]
1170735
def truncate(string, len = 128)
      stripped = string.strip[0..len]
      if stripped.length > len
        stripped.gsub(/\s+?(\S+)?$/, "") + "..."
      else
        stripped
      end
    end
97934
def random_string(length):
    
    # avoid things that could be mistaken ex: 'I' and '1'
    letters = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ"
    return "".join([random.choice(letters) for _ in range(length)])