Returns an substring defined by startPosition and length

@param int $startPosition
@param int $length
@return string
@throws \InvalidArgumentException
178148
public function buildSubstring($startPosition, $length = null)
	{
		ArgumentValidator::validateUnsignedInteger($startPosition);
		ArgumentValidator::validateUnsignedIntegerOrNull($length);
		if ($startPosition >= $this->length()) {
			throw new \InvalidArgumentException('Start position ' . (string)$startPosition . ' invalid');
		}
		if ($length === null) {
			return mb_substr($this->string, $startPosition);
		}
		return mb_substr($this->string, $startPosition, $length);
	}
916252
public static function truncate_two($str, $start, $length = null)
    {
        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;
    }
1314856
static function substring($input, $start, $length = null) {
		return self::substr($input, $start, $length, "utf-8");
	}
820791
public function substr($start, $length = null, $encoding = null)
    {
        return $this->addModifier('substr', array($start, $length, $encoding));
    }
1288238
public static function findCharPosition($string, $char, $startAt = 0)
    {
        $position = strpos($string, $char, $startAt);

        return ($position !== false) ? $position + 1 : null;
    }
32633
public static function substrForGbk($string, $start, $length = null, $dot = false)
	{
		$l = strlen($string);
		$p = $s = 0;
		if (0 !== $start)
		{
			while ($start-- && $p < $l)
			{
				if ($string[$p] > "\x80")
					$p += 2;
				else
					$p++;
			}
			$s = $p;
		}
		
		if (empty($length))
		{
			$t = substr($string, $s);
		}
		else
		{
			$i = $length;
			while ($i-- && $p < $l)
			{
				if ($string[$p] > "\x80")
					$p += 2;
				else
					$p++;
			}
			$t = substr($string, $s, $p - $s);
		}
		
		$dot && ($p < $l) && $t .= "...";
		return $t;
	}
867448
public function substr($str, $offset = 0, $length = null)
    {
        return mb_substr($str, $offset, $length, $this->getEncoding());
    }
1193657
public static function betweenSubstr($string, $start, $end = null)
    {
        if (($start_pos = strpos($string, $start)) !== false) {
            if ($end) {
                if (($end_pos = strpos($string, $end, $start_pos + strlen($start))) !== false) {
                    return substr($string, $start_pos + strlen($start), $end_pos - ($start_pos + strlen($start)));
                }
            } else {
                return substr($string, $start_pos);
            }
        }
        return false;
    }
1173738
private static function substr($str, $start, $len)
    {
        if (function_exists('mb_substr'))
        {
            return mb_substr($str, $start, $len, 'UTF-8');
        }
        else
        {
            return substr($str, $start, $len * 2);
        }
    }
591935
private function isNextLineEmpty(int $startPosition): bool
    {
        $istNextLineEmpty = true;
        $nextRelevantPos = $this->loadNextDocBlockContent($startPosition);

        if ($nextRelevantPos !== -1) {
            $istNextLineEmpty = $this->tokens[$startPosition]['line'] + 1 < $this->tokens[$nextRelevantPos]['line'];
        }

        return $istNextLineEmpty;
    }
733126
protected function doInsertStringBeforePosition(string $string, string $insertStr, int $position): string
    {
        return \substr($string, 0, $position) . $insertStr . \substr($string, $position);
    }
443112
public function slice($start, $length = null)
    {
        $answer = new HStringSlice($this);
        return new static($answer->slice($start, $length));
    }
310797
public function at($start = null, $length = null)
    {
        return new String(mb_substr((string) $this, $start, $length, 'UTF-8'));
    }
613088
public static function substring($string, $startpos, $endpos = -1)
    {
        $len = strlen($string);
        $endpos = (int) (($endpos === -1) ? $len - 1 : $endpos);
        if ($startpos > $len - 1 || $startpos < 0) {
            trigger_error("substring(), Startindex out of bounds must be 0<n<$len", E_USER_ERROR);
        }
        if ($endpos > $len - 1 || $endpos < $startpos) {
            trigger_error("substring(), Endindex out of bounds must be $startpos<n<" . ($len - 1), E_USER_ERROR);
        }
        if ($startpos === $endpos) {
            return (string) $string{$startpos};
        } else {
            $len = $endpos - $startpos;
        }

        return substr($string, $startpos, $len + 1);
    }
851035
public function slice( int$start=0, int...$lengths ):string
	{
		return substr($this->getContent(),$start,...array_slice($lengths,0,1));
	}
648277
public function cut($start, $length = null)
    {
        return $this->addRule(new FilterRule\Cut($start, $length));
    }
893382
public static function slice($string, $start, $length = null)
    {
        if (function_exists('mb_substr')) {
            return mb_substr($string, $start, $length, '8bit');
        }
        return substr($string, $start, $length);
    }