REPLACE

@param    string    $oldText    String to modify
@param    int        $start        Start character
@param    int        $chars        Number of characters
@param    string    $newText    String to replace in defined position
@return    string
198162
public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText)
    {
        $oldText = PHPExcel_Calculation_Functions::flattenSingleValue($oldText);
        $start   = PHPExcel_Calculation_Functions::flattenSingleValue($start);
        $chars   = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
        $newText = PHPExcel_Calculation_Functions::flattenSingleValue($newText);

        $left = self::LEFT($oldText, $start-1);
        $right = self::RIGHT($oldText, self::STRINGLENGTH($oldText)-($start+$chars)+1);

        return $left.$newText.$right;
    }
301501
public static function substr_replace($string, $replacement, $start , $length=null )
    {
        $ret = '';
        if($start>0) $ret .= self::substr($string, 0, $start);
        $ret .= $replacement;
        if($length!=null) $ret .= self::substr($string, $start+$length);
        return $ret;
    }
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]);
    }
1068553
private function replacePlaceholdersInText($text): string
    {
        $text = str_replace(array_keys($this->placeholders), $this->placeholders, $text);
        
        return $text;
    }
550181
private void mapText(String oldText, Map<String, String> replacements)
   {
      char c2 = 0;
      if (oldText != null && oldText.length() != 0 && !replacements.containsKey(oldText))
      {
         StringBuilder newText = new StringBuilder(oldText.length());
         for (int loop = 0; loop < oldText.length(); loop++)
         {
            char c = oldText.charAt(loop);
            if (Character.isUpperCase(c))
            {
               newText.append('X');
            }
            else
            {
               if (Character.isLowerCase(c))
               {
                  newText.append('x');
               }
               else
               {
                  if (Character.isDigit(c))
                  {
                     newText.append('0');
                  }
                  else
                  {
                     if (Character.isLetter(c))
                     {
                        // Handle other codepages etc. If possible find a way to
                        // maintain the same code page as original.
                        // E.g. replace with a character from the same alphabet.
                        // This 'should' work for most cases
                        if (c2 == 0)
                        {
                           c2 = c;
                        }
                        newText.append(c2);
                     }
                     else
                     {
                        newText.append(c);
                     }
                  }
               }
            }
         }

         replacements.put(oldText, newText.toString());
      }
   }
573250
public function truncateHtmlText($text, $characters = 300)
    {
        // Clean up html tags and special characters
        $text = preg_replace('/<[^>]*>/', ' ', $text);
        $text = str_replace("\r", '', $text); // replace with empty space
        $text = str_replace("\n", ' ', $text); // replace with space
        $text = str_replace("\t", ' ', $text); // replace with space
        $text = preg_replace('/\s+/', ' ', $text); // remove multiple consecutive spaces
        $text = preg_replace('/^[\s]/', '', $text); // Remove leading space from excerpt
        $text = preg_replace('/[\s]$/', '', $text); // Remove trailing space from excerpt

        // If we are already within the limit, just return the text
        if (mb_strlen($text) <= $characters) {
            return $text;
        }

        // Truncate to character limit if longer than requested
        $text = substr($text, 0, $characters);

        // We don't want the string cut mid-word, so search for the last space and trim there
        $lastSpacePosition = strrpos($text, ' ');
        if (isset($lastSpacePosition)) {
            // Cut the text at this last word
            $text = substr($text, 0, $lastSpacePosition);
        }

        return $text;
    }
84571
public MultiChangeBuilder<PS, SEG, S> deleteText(int start, int end) {
        return replaceText(start, end, "");
    }
923681
protected function removeChar($string, $charStart = null, $charEnd = null)
    {
        if (!is_null($charStart) && (is_string($charStart) || is_array($charStart))) {
            if (is_string($charStart)) {
                $charStart = [$charStart];
            }

            foreach ($charStart as $char) {
                if (substr($string, 0, 1) === $char) {
                    $string = substr($string, 1);
                }
            }
        }

        if (!is_null($charEnd) && (is_string($charEnd) || is_array($charEnd))) {
            if (is_string($charEnd)) {
                $charEnd = [$charEnd];
            }

            foreach ($charEnd as $char) {
                if (substr($string, -1) === $char) {
                    $string = substr($string, 0, -1);
                }
            }
        }

        return $string;
    }
1033492
public function remove($startIndex, $length)
    {
        $start = UTF8::substr
        (
            (string)$this->str,
            0,
            $startIndex,
            $this->str->getEncoding()
        );

        $end = UTF8::substr
        (
            (string)$this->str,
            $startIndex + $length,
            $this->str->getLength(),
            $this->str->getEncoding()
        );

        $this->str = new Str($start.$end);

        return $this;
    }
729669
public void replace(StringBuilder sb, CharSequence text)
    {
        if (!isCompiled())
        {
            compile();
        }
        DFAState<Replacer> st = root;
        Replacer replacer = null;
        int start = -1;
        int end = -1;
        int len = text.length();
        for (int ii=0;ii<len;ii++)
        {
            char cc = text.charAt(ii);
            st = st.transit(cc);
            if (st != null)
            {
                if (start == -1)
                {
                    start = ii; // start of match
                }
                if (st.isAccepting())
                {
                    end = ii;   // last accpting point
                    replacer = st.getToken();
                }
            }
            else
            {
                // error
                if (start != -1)
                {
                    // we have some matching
                    if (end != -1)
                    {
                        // accepted string
                        replacer.replace(sb, text, start, end+1);
                        ii = end;   // reparse after last match
                        end = -1;
                    }
                    else
                    {
                        // not accepted partial match
                        sb.append(text, start, ii+1);
                    }
                    start = -1;
                }
                else
                {
                    sb.append(cc);
                }
                st = root;
            }
        }
        if (start != -1)
        {
            // matching at end
            if (end != -1)
            {
                replacer.replace(sb, text, start, end+1);
            }
            else
            {
                sb.append(text, start, len);
            }
        }
    }
324713
public AsciiString replace(char oldChar, char newChar) {
        if (oldChar > MAX_CHAR_VALUE) {
            return this;
        }

        final byte oldCharAsByte = c2b0(oldChar);
        final byte newCharAsByte = c2b(newChar);
        final int len = offset + length;
        for (int i = offset; i < len; ++i) {
            if (value[i] == oldCharAsByte) {
                byte[] buffer = PlatformDependent.allocateUninitializedArray(length());
                System.arraycopy(value, offset, buffer, 0, i - offset);
                buffer[i - offset] = newCharAsByte;
                ++i;
                for (; i < len; ++i) {
                    byte oldValue = value[i];
                    buffer[i - offset] = oldValue != oldCharAsByte ? oldValue : newCharAsByte;
                }
                return new AsciiString(buffer, false);
            }
        }
        return this;
    }
919291
protected function diffElements($oldText, $newText, $stripWrappingTags = true)
    {
        $wrapStart = '';
        $wrapEnd = '';

        if ($stripWrappingTags) {
            $pattern = '/(^<[^>]+>)|(<\/[^>]+>$)/iu';
            $matches = array();

            if (preg_match_all($pattern, $newText, $matches)) {
                $wrapStart = isset($matches[0][0]) ? $matches[0][0] : '';
                $wrapEnd = isset($matches[0][1]) ? $matches[0][1] : '';
            }
            $oldText = preg_replace($pattern, '', $oldText);
            $newText = preg_replace($pattern, '', $newText);
        }

        $diff = self::create($oldText, $newText, $this->config);

        return $wrapStart.$diff->build().$wrapEnd;
    }
191855
public static function replaceUrl($content, $oldPrefix, $newPrefix)
    {
        $replacedUrl = preg_replace(
            '#(.*?)/' . preg_quote($oldPrefix, '#') . '(.*?)#',
            '$1/' . $newPrefix . '$2',
            $content
        );
    
        return $replacedUrl;
    }
604573
public static function replace($text, array $replacements = [], $prefix = '{', $suffix = '}')
    {
        $replacements = static::prepareBinding($replacements, $prefix, $suffix);

        $filter = function ($text) use ($replacements) {
            return strtr($text, $replacements);
        };

        if (is_array($text)) {
            $text = array_map($filter, $text);
        } else {
            $text = $filter($text);
        }

        return $text;
    }
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;
    }
820791
public function substr($start, $length = null, $encoding = null)
    {
        return $this->addModifier('substr', array($start, $length, $encoding));
    }
1291270
public static function substr($string, $start, $length, $dot = false, $charset = self::UTF8)
	{
		switch (strtolower($charset))
		{
			case self::GBK:
				$string = self::substrForGbk($string, $start, $length, $dot);
				break;
			case self::UTF8:
				$string = self::substrForUtf8($string, $start, $length, $dot);
				break;
			default:
				$string = substr($string, $start, $length);
		}
		return $string;
	}