@@ 196-211 (lines=16) @@ | ||
193 | * |
|
194 | * @return \Spatie\String\Str |
|
195 | */ |
|
196 | public function replaceFirst($search, $replace) |
|
197 | { |
|
198 | if ($search == '') { |
|
199 | return $this; |
|
200 | } |
|
201 | ||
202 | $position = strpos($this->string, $search); |
|
203 | ||
204 | if ($position === false) { |
|
205 | return $this; |
|
206 | } |
|
207 | ||
208 | $resultString = substr_replace($this->string, $replace, $position, strlen($search)); |
|
209 | ||
210 | return new static($resultString); |
|
211 | } |
|
212 | ||
213 | /** |
|
214 | * Replace the last occurrence of a string. |
|
@@ 221-236 (lines=16) @@ | ||
218 | * |
|
219 | * @return \Spatie\String\Str |
|
220 | */ |
|
221 | public function replaceLast($search, $replace) |
|
222 | { |
|
223 | if ($search == '') { |
|
224 | return $this; |
|
225 | } |
|
226 | ||
227 | $position = strrpos($this->string, $search); |
|
228 | ||
229 | if ($position === false) { |
|
230 | return $this; |
|
231 | } |
|
232 | ||
233 | $resultString = substr_replace($this->string, $replace, $position, strlen($search)); |
|
234 | ||
235 | return new static($resultString); |
|
236 | } |
|
237 | ||
238 | /** |
|
239 | * Prefix a string. |