예제 #1
0
 public function testReplaceSubstring()
 {
     $this->eq(s::replaceSubstring('abcdef', 'x', 2, 3), 'abxf');
     $this->eq(s::replaceSubstring('abcdef', 'x', 2), 'abx');
     $this->eq(s::replaceSubstring('abcdef', 'x', 2, 1000), 'abx');
     $this->eq(s::replaceSubstring('abcdef', 'x', 1000), 'abcdefx');
     $this->eq(s::replaceSubstring('abcdef', 'x', 1000, 3), 'abcdefx');
     $this->eq(s::replaceSubstring('abcdef', 'x', 2, 0), 'abxcdef');
     $this->eq(s::replaceSubstring('abcdef', 'x', -2), 'abcdx');
     $this->eq(s::replaceSubstring('abcdef', 'x', -4, 2), 'abxef');
     $this->eq(s::replaceSubstring('abcdef', 'x', -1000), 'x');
     $this->eq(s::replaceSubstring('abcdef', 'x', -1000, -100), 'xabcdef');
     $this->eq(s::replaceSubstring('abcdef', 'x', -7, 3), 'xcdef');
     $this->eq(s::replaceSubstring('', 'x', 2, 4), 'x');
 }
예제 #2
0
 public function replaceSubstring($new, $offset, $length = null)
 {
     return new self(s::replaceSubstring($this->value, self::unwrap($new), $offset, $length));
 }