Skip to content

Commit d62fe02

Browse files
[11.x] Document Str::deduplicate method (laravel#9890)
* [11.x] Document Str::deduplicate method * Fix order (alphabetical) * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 510dd2e commit d62fe02

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

strings.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Laravel includes a variety of functions for manipulating string values. Many of
4747
[Str::chopEnd](#method-str-chop-end)
4848
[Str::contains](#method-str-contains)
4949
[Str::containsAll](#method-str-contains-all)
50+
[Str::deduplicate](#method-deduplicate)
5051
[Str::endsWith](#method-ends-with)
5152
[Str::excerpt](#method-excerpt)
5253
[Str::finish](#method-str-finish)
@@ -141,6 +142,7 @@ Laravel includes a variety of functions for manipulating string values. Many of
141142
[chopEnd](#method-fluent-str-chop-end)
142143
[contains](#method-fluent-str-contains)
143144
[containsAll](#method-fluent-str-contains-all)
145+
[deduplicate](#method-fluent-str-deduplicate)
144146
[dirname](#method-fluent-str-dirname)
145147
[endsWith](#method-fluent-str-ends-with)
146148
[exactly](#method-fluent-str-exactly)
@@ -466,6 +468,25 @@ You may disable case sensitivity by setting the `ignoreCase` argument to `true`:
466468

467469
// true
468470

471+
<a name="method-deduplicate"></a>
472+
#### `Str::deduplicate()` {.collection-method}
473+
474+
The `Str::deduplicate` method replaces consecutive instances of a character with a single instance of that character in the given string. By default, the method deduplicates spaces:
475+
476+
use Illuminate\Support\Str;
477+
478+
$result = Str::deduplicate('The Laravel Framework');
479+
480+
// The Laravel Framework
481+
482+
You may specify a different character to deduplicate by passing it in as the second argument to the method:
483+
484+
use Illuminate\Support\Str;
485+
486+
$result = Str::deduplicate('The---Laravel---Framework', '-');
487+
488+
// The-Laravel-Framework
489+
469490
<a name="method-ends-with"></a>
470491
#### `Str::endsWith()` {.collection-method}
471492

@@ -1744,6 +1765,25 @@ You can disable case sensitivity by setting the `ignoreCase` argument to `true`:
17441765

17451766
// true
17461767

1768+
<a name="method-fluent-str-deduplicate"></a>
1769+
#### `deduplicate` {.collection-method}
1770+
1771+
The `deduplicate` method replaces consecutive instances of a character with a single instance of that character in the given string. By default, the method deduplicates spaces:
1772+
1773+
use Illuminate\Support\Str;
1774+
1775+
$result = Str::of('The Laravel Framework')->deduplicate();
1776+
1777+
// The Laravel Framework
1778+
1779+
You may specify a different character to deduplicate by passing it in as the second argument to the method:
1780+
1781+
use Illuminate\Support\Str;
1782+
1783+
$result = Str::of('The---Laravel---Framework')->deduplicate('-');
1784+
1785+
// The-Laravel-Framework
1786+
17471787
<a name="method-fluent-str-dirname"></a>
17481788
#### `dirname` {.collection-method}
17491789

0 commit comments

Comments
 (0)