Reduce the strings.

@param   int $start  Position of first character.
@param   int $length Maximum number of characters.

@return  self
2143
public function reduce($start, $length = null)
    {
        $this->_string = \mb_substr($this->_string, $start, $length);

        return $this;
    }
964419
public function slice($start=0, $end=-1) {
        if ( $end == -1 ) return substr($this->internal, $start);
        $len = $end - $start - 1;
        return substr($this->internal, $start, $len);
    }
541000
public static function startsWith($value, $start)
    {

        if (is_array($value)) {
            return self::first($value) == $start;
        }

        return mb_strpos("$value", "$start") === 0;

    }
632498
public function crop($start, $length = null)
    {
        $this->setInternalValue(mb_substr($this->getInternalValue(), $start, $length, 'UTF-8'));

        return $this;
    }
310797
public function at($start = null, $length = null)
    {
        return new String(mb_substr((string) $this, $start, $length, 'UTF-8'));
    }
1176034
function _substr($string, $start, $length = null) {
        static $mbstring;

        // Cache expensive function_exists() calls.
        if (!isset($mbstring)) {
            $mbstring = function_exists('mb_substr');
        }

        if (is_null($length)) {
            $length = $this->_strlen($string);
        }
        if ($mbstring) {
            $ret = @mb_substr($string, $start, $length, $this->_charset);
            if (!empty($ret)) {
                return $ret;
            }
        }
        return substr($string, $start, $length);
    }
177205
public function substring(int $start, int $length = null): self
    {
        if ($this->length() === 0) {
            return $this;
        }

        $sub = \mb_substr($this->value, $start, $length, (string) $this->encoding());

        return new self($sub, $this->encoding);
    }
679625
protected function _bufferSize($length)
    {
        if ($this->_limit !== null) {
            $position = $this->tell();
            $max = $this->_start + $this->_limit;
            $length = $max - $position;
        }
        if ($length === null) {
            $length = $this->_bufferSize;
        }
        return $length;
    }
820791
public function substr($start, $length = null, $encoding = null)
    {
        return $this->addModifier('substr', array($start, $length, $encoding));
    }
1081399
public function pagination($start = 1, $length = 10)
	{
		// manually create paginator
		$data = array_map(function ($num) {
			return ['id' => $num, 'value' => "Item $num"];
		}, range(1, 100));
		$page = Paginator::resolveCurrentPage('page');
		$path = Paginator::resolveCurrentPath();
		$items = array_slice($data, abs($start - 1) + (($page - 1) * $length), $length);
		$paginator = new LengthAwarePaginator($items, count($data), $length, $page, [
			'path'     => $path,
			'pageName' => 'page',
		]);

		// append existing parameters
		$paginator->appends(Sketchpad::$params);

		// output
		return view('sketchpad::help/output/pagination', compact('items', 'paginator'));

	}
1038765
private function _remove(int $start, int $length = null) : array
    {
        $values = $this->getValues();
        if ($length){
            array_splice($values, $start, $length);
        }
        else{
            array_splice($values, $start);
        }
        return $values;
    }
1282817
private function validateStartLength($start, $length)
    {
        $_startEnd = [];
        if (preg_match('/[0-9]/', $start)) {
            $_startEnd[0] = (int) $start;
        } elseif ('#' === $start) {
            $_startEnd[0] = '#';
        } else {
            throw new \UnexpectedValueException(
                'First argument must be positive int, 0 or character #.',
                $start
            );
        }

        if (preg_match('/^[1-9]\d*/', $length)) { // only positive int without 0
            $_startEnd[1] = (int) $length - 1;
        } else {
            throw new \UnexpectedValueException(
                'Second argument must be positive int without 0.',
                $length
            );
        }

        return $_startEnd;
    }
1168561
public static function substr_replace($str, $repl, $start, $length = null)
    {
        preg_match_all('/./us', $str, $ar);
        preg_match_all('/./us', $repl, $rar);
        if ($length === null) {
            $length = AnHelperString::strlen($str);
        }
        array_splice($ar[0], $start, $length, $rar[0]);
        return join('', $ar[0]);
    }
910358
public static function substr(string $string, int $start, int $length = null): string
    {
        return \mb_substr($string, $start, $length, '8bit');
    }
360804
public function substr($start = 0, $length = null)
    {
        $function = static::$functions[(int) static::$useMbstring]['substr'];

        return new self($function($this->string, $start, $length));
    }
434439
public function limit($start, $offset = null) {
        $this->_limit = ' LIMIT ' . $start;
        
        if (!is_null($offset)) {
            $this->_limit .= ', ' . $offset;    
        }
        
        return $this;
    }
985373
private function fillBuffer($length)
    {
        $fill = intval(max([$length, 8192]));
        while ($this->buffer->getSize() < $length) {
            $read = $this->stream->read($fill);
            if ($read === false || $read === '') {
                break;
            }
            $this->buffer->write(preg_replace($this->pattern, $this->replacement, $read));
        }
    }