Return part of the string

@param int $start
@param int $length

@return self
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);
    }
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;
    }
496886
function(str, start) {
    return (str.length >= start.length &&
            str.substr(0, start.length) === start);
  }
1286656
public function range(int $start, int $length): string
    {
        if (!$length) {
            return "0";
        }
        if ($start + $length > $this->numBits()) {
            throw new \OutOfBoundsException("Not enough bits.");
        }
        $bits = gmp_init(0);
        $idx = $start;
        $end = $start + $length;
        while (true) {
            $bit = $this->testBit($idx) ? 1 : 0;
            $bits |= $bit;
            if (++$idx >= $end) {
                break;
            }
            $bits <<= 1;
        }
        return gmp_strval($bits, 10);
    }
758458
public function substr($key, $start, $end) {
        return $this->returnCommand(['SUBSTR'], $key, [$key, $start, $end]);
    }
316634
public static function binarySubstr($str, $start, $length) {
		if (function_exists('mb_substr')) {
			return mb_substr($str, $start, $length, '8bit');
		}

		return substr($string, $start, $length);
	}
1269408
public static function sub($str, $start, $length = null, $encoding = null) {
        $encoding or $encoding = \Fuel::$encoding;
        // substr functions don't parse null correctly
        $length = is_null($length) ? (function_exists('mb_substr') ? mb_strlen($str, $encoding) : strlen($str)) - $start : $length;
        return function_exists('mb_substr') ? mb_substr($str, $start, $length, $encoding) : substr($str, $start, $length);
    }
216408
public static function substr(string $str, int $start=0, $length=null) {
		if (\function_exists('mb_substr')) {
			return \mb_substr($str, $start, $length, 'UTF-8');
		}

		return \substr($str, $start, $length);
	}
231642
public function transform(string $value, int $start = 0, int $length = null): string {
        return $length === null ? substr($value, $start) : substr($value, $start, $length);
    }
1115730
public function subString($startPosition, $length)
    {
        if (!$this->isNumber($startPosition)) {
            throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [
                '$startPosition',
                'integer'
            ]);
        }

        if (!$this->isNumber($length)) {
            throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [
                '$length',
                'integer'
            ]);
        }

        if ($length == 0) {
            $length = null;
        }
        $value = mb_substr($this->val(), $startPosition, $length, self::DEF_ENCODING);
        $this->val($value);

        return $this;
    }
920681
function split($start, $length = null)
    {
        $return = clone $this;
        $path   = array_slice($this->getPath(), $start, $length);
        $return->setPath($path);

        return $return;
    }
483441
protected static function ourSubstr($str, $start = 0, $length = null)
    {
        // Premature optimization: cache the function_exists() result
        static $exists = null;
        if ($exists === null) {
            $exists = \function_exists('\\mb_substr');
        }

        // If it exists, we need to make sure we're using 8bit mode
        if ($exists) {
            return \mb_substr($str, $start, $length, '8bit');
        } elseif ($length !== null) {
            return \substr($str, $start, $length);
        }
        return \substr($str, $start);
    }
335492
public static function sub(string $string, int $start, ?int $length = null, string $encode = 'UTF-8'): ?string
    {
        return mb_substr($string, $start, $length, $encode);
    }
190082
public static function substr($str, $start = 0, $len = 50)
    {
        return mb_strlen($str) > $len ? mb_substr($str, $start, $len, 'UTF-8') . "…" : $str;
    }
569318
public function substringBetween($start, $end)
    {
        $ini = mb_stripos($this->str, $start, 0, $this->encoding);

        if ($ini === 0) {
            return "";
        }

        $ini += mb_strlen($start, $this->encoding);
        $len = mb_stripos($this->str, $end, $ini, $this->encoding) - $ini;

        return static::create(mb_substr($this->str, $ini, $len, $this->encoding), $this->encoding);
    }
797437
public function slice($from, $length = null) {
        if ($length === null) {
            return substr($this->buffer, $from);
        }

        return substr($this->buffer, $from, $length);
    }
1316806
private static function substr($str,$start,$length=null)
    {
        $ar = array();
        preg_match_all("/./u", $str, $ar);

        if($length != null) {
            return join("",array_slice($ar[0],$start,$length));
        } else {
            return join("",array_slice($ar[0],$start));
        }
    }