*
Return formatted string to send in PagSeguro request
@param string $string
@param int $limit
@param mixed $endchars
@return string
162570
public static function formatString($string, $limit, $endchars = '...')
    {
        $string = PagSeguroHelper::removeStringExtraSpaces($string);
        return PagSeguroHelper::truncateValue($string, $limit, $endchars);
    }
1266827
public function takeAllUntil(string $ends): string
    {
        $ends = self::split($ends);

        $ends[] = self::END;

        $taken = "";

        while (!in_array($this->peek(), $ends)) {
            $char = $this->take();

            $taken .= $char;
        }

        return $taken;
    }
942906
protected function textCamelToUnderscoreStripFirstToken($string)
    {
        $camelized_string_tokens = preg_split('/(?<=\\w)(?=[A-Z])/', $string);
        array_shift($camelized_string_tokens);
        if (count($camelized_string_tokens) > 0) {
            return mb_strtolower(implode('_', $camelized_string_tokens));
        }

        return $string;
    }
1224779
public function limitWord($string, $limit = 10)
    {
        $words = explode(" ", $string);
        return implode(" ", array_splice($words, 0, $limit));
    }
544367
public static function cutWords(string $string, int $limit = 25, string $append = '...'): string
    {
        preg_match('/^\s*+(?:\S++\s*+){1,' . $limit . '}/u', $string, $matches);
        if (!isset($matches[0]) || mb_strlen($string, 'UTF-8') === mb_strlen($matches[0], 'UTF-8')) {
            return $string;
        }

        return rtrim($matches[0]) . $append;
    }
363983
protected function truncate($string, $limit, $pad = '...', $break = ' ')
    {
        // return with no change if string is shorter than $limit
        if(strlen($string) <= $limit) return $string;

        // is $break present between $limit and the end of the string?
        if(false !== ($breakpoint = strpos($string, $break, $limit))) {
            if($breakpoint < strlen($string) - 1) {
                $string = substr($string, 0, $breakpoint) . $pad;
            }
        }

        return $string;
    }
108480
public static function hideString($string, $start, $end, $replace = "*")
    {
        $length = strlen($string);
        $result = '';

        if ($start >= $length) {
            return $result;
        }
        if ($end <= $start) {
            return $result;
        }

        for ($i = 0; $i < $length; $i++) {
            $result .= $i >= $start && $i <= $end ? $replace : $string[$i];
        }
        return $result;
    }
735754
function _convertString($string)
    {
        // chop away beggining and ending quotes
        $string = substr($string, 1, strlen($string) - 2);
        if (strlen($string) > 255) {
            return $this->raiseError("String is too long");
        }

        if ($this->_BIFF_version == 0x0500) {
            return pack("CC", $this->ptg['ptgStr'], strlen($string)).$string;
        } elseif ($this->_BIFF_version == 0x0600) {
            $encoding = 0;   // TODO: Unicode support
            return pack("CCC", $this->ptg['ptgStr'], strlen($string), $encoding).$string;
        }
    }
313527
public static function slice($str, $start, $end = null)
    {
        $sliceStr = '';

        if (is_string($str)) {
            if ($end === null) {
                $end = static::len($str);
            }

            if ($start < $end) {
                $sliceStr = mb_substr($str, $start, $end, 'UTF-8');
            }
        }

        return $sliceStr;
    }
1083519
public function endsWith($string)
    {
        $string = StdObjectWrapper::toString($string);

        // calculate the end position
        $length = strlen($string);
        $endString = substr($this->val(), -$length);

        if ($string == $endString) {
            return true;
        }

        return false;
    }
1101338
public static function endsWith($string, $suffix) {
    return (mb_strrpos($string,$suffix) === mb_strlen($string) - mb_strlen($suffix));
  }
103691
function between($str, $start, $end = null, $greed = true)
    {
        if (isset($start)) {
            $pos1 = strpos($str, $start);
        } else {
            $pos1 = 0;
        }
        if (isset($end)) {
            if ($greed) {
                $pos2 = strrpos($str, $end);
            } else {
                $pos2 = strpos($str, $end, $pos1);
            }
        } else {
            $pos2 = strlen($str);
        }
        if (false === $pos1 || false === $pos2 || $pos2 < $pos1) {
            return '';
        }
        $len = strlen($start);
        return substr($str, $pos1 + $len, $pos2 - $pos1 - $len);
    }
495785
public static function limit(string $value, int $limit = 50, string $end = self::LIMIT_SUFFIX): string
    {
        if (mb_strwidth($value, 'UTF-8') <= $limit) {
            return $value;
        }
        return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end;
    }
722957
protected function limitedText($text, $limit = 200)
    {
        $postString = '...';
        $strCount = strlen(trim($text));
        $sLimitedText = $text;

        if($strCount > $limit)
        {
            $sLimitedText = substr($text, 0, $limit) . $postString;
        }

        return $sLimitedText;

    }
1029706
public static function mustEndWith($character = '/', $string = ''){
        if (strlen($string) > 0) {
            if (substr($string, strlen($string) -1, 1) != $character) {
                return $string . $character;
            } else {
                return $string;
            }
        } else {
            return $character;
        }
    }
607130
protected function limitConsecutiveNewlines($string, $limit = 2)
    {
        // Pattern that finds any consecutive newlines that exceed the allowed limit.
        $exceeded = $limit + 1;
        $pattern = '/((\\n){' . $exceeded . ',})/';

        // Create a string with the maximum number of allowed newlines.
        $newlines = '';
        for ($i = 0; $i < $limit; $i++) {
            $newlines .= PHP_EOL;
        }

        // Find each match and replace it with the maximum number of newlines.
        return preg_replace($pattern, $newlines, $string);
    }
478105
public function doesStringEndWith(string $string, string $test): bool {
		$strlen = strlen($string);
		$testlen = strlen($test);
		if ($testlen > $strlen) {
			return false;
		}
		return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0;
	}