Returns a new string with the suffix $substring removed, if present.

@param  string $substring The suffix to remove.

@return static            String without the suffix $substring.
518001
public function removeRight($substring)
    {
        if ($this->endsWith($substring))
        {
            return $this->newSelf
            (
                UTF8::substr
                (
                    $this->scalarString,
                    0,
                    $this->getLength() - UTF8::strlen($substring, $this->encoding),
                    $this->encoding
                )
            );
        }

        return $this;
    }
1221542
private function endswith($string, $suffix)
	{
		$strlen = strlen($string);
		$testlen = strlen($suffix);
		if ($testlen > $strlen) {
			return false;
		}

		return substr_compare($string, $suffix, -$testlen) === 0;
	}
985844
public static function substringBefore($string, $separator)
    {
        $pos = mb_strpos($string, $separator);
        return $pos !== false ? mb_substr($string, 0, $pos) : $string;
    }
1106696
protected static function stripPrefix(string $string, string $prefix): string {
        if(strpos($string, $prefix) !== 0) {
            return $string;
        }
        return substr($string, strlen($prefix));
    }
1329755
public function insert($substring, $index)
    {
        $stringy = static::create($this->str, $this->encoding);
        if ($index > $stringy->length()) {
            return $stringy;
        }

        $start = \mb_substr($stringy->str, 0, $index, $stringy->encoding);
        $end = \mb_substr($stringy->str, $index, $stringy->length(),
            $stringy->encoding);

        $stringy->str = $start . $substring . $end;

        return $stringy;
    }
532515
private function stringEndsWith(string $string, string $suffix): bool
    {
        return substr($string, -strlen($suffix)) === $suffix;
    }
63770
public function ensureRight($substring) {
        $stringy = self::create($this->str, $this->encoding);

        if (!$stringy->endsWith($substring))
            $stringy->str .= $substring;

        return $stringy;
    }
378939
public static function makeByString($string)
    {
        $fg = $bg = '';
        $extra = false;
        $options = [];
        $parts = \explode(';', \str_replace(' ', '', $string));

        foreach ($parts as $part) {
            $subParts = \explode('=', $part);

            if (\count($subParts) < 2) {
                continue;
            }

            switch ($subParts[0]) {
                case 'fg':
                    $fg = $subParts[1];
                    break;
                case 'bg':
                    $bg = $subParts[1];
                    break;
                case 'extra':
                    $extra = (bool)$subParts[1];
                    break;
                case 'options':
                    $options = \explode(',', $subParts[1]);
                    break;
                default:
                    throw new \RuntimeException('Invalid option');
                    break;
            }
        }

        return new self($fg, $bg, $options, $extra);
    }
506178
public function ensureSuffix($substring, $encoding = null)
    {
        if (!$this->hasMbstring()) {
            $len = \strlen($substring);
            if (\substr($this->string, -$len) == $substring) {
                return $this;
            }
        } else {
            $encoding = $this->encoding($encoding);

            $len = \mb_strlen($substring, $encoding);
            if (\mb_substr($this->string, -$len, \mb_strlen($this->string, $encoding), $encoding) == $substring) {
                return $this;
            }
        }

        return $this->suffix($substring);
    }
787691
public String removeSuffix(String original, String suffix) {
        if (original.endsWith(suffix)) {
            return original.substring(0, original.length() - suffix.length());
        }
        return original;
    }
618379
static function fromString(string $string): self
    {
        $string = str_replace("/", "\\", $string);
        $string = preg_replace("#(\\\\){2,}#", "\\", $string);
        if (substr($string, -1, 1) == "\\") {
            $string = substr($string, 0, -1);
        }
        
        return new self($string);
    }
337029
protected function prefixSuffix($string)
    {
        $prefix = ltrim($string) !== $string ? ' ' : '';

        $suffix = rtrim($string) !== $string ? ' ' : '';

        return (array) array($prefix, $suffix);
    }
367044
public static function removePunctuation($string)
    {
        $string = self::removeTrailingPunctuation($string);
        $string = self::removeLeadingPunctuation($string);
        return $string;
    }
1292572
public function ensurePrefix($substring, $encoding = null)
    {
        if (!$this->hasMbstring()) {
            $len = \strlen($substring);
            if (\substr($this->string, 0, $len) == $substring) {
                return $this;
            }
        } else {
            $encoding = $this->encoding($encoding);
            $len = \mb_strlen($substring, $encoding);
            if (\mb_substr($this->string, 0, $len, $encoding) == $substring) {
                return $this;
            }
        }

        return $this->prefix($substring);
    }
527705
public function ensureLeft($substring) {
        $stringy = self::create($this->str, $this->encoding);

        if (!$stringy->startsWith($substring))
            $stringy->str = $substring . $stringy->str;

        return $stringy;
    }
768875
public static function substring($string, $from, $to) {
    return mb_substr($string, $from, abs($from-$to));
  }
229990
public static function fromString($sortingString)
    {
        $parts = GeneralUtility::trimExplode(' ', $sortingString);
        return new Sorting(true, $parts[0], $parts[1]);
    }