Skip to content

Commit 6e19bf5

Browse files
authored
[12.x] Add new string methods (#10569)
* wip * wip
1 parent 6c78ad4 commit 6e19bf5

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

strings.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Laravel includes a variety of functions for manipulating string values. Many of
4848
[Str::contains](#method-str-contains)
4949
[Str::containsAll](#method-str-contains-all)
5050
[Str::doesntContain](#method-str-doesnt-contain)
51+
[Str::doesntEndWith](#method-str-doesnt-end-with)
52+
[Str::doesntStartWith](#method-str-doesnt-start-with)
5153
[Str::deduplicate](#method-deduplicate)
5254
[Str::endsWith](#method-ends-with)
5355
[Str::excerpt](#method-excerpt)
@@ -149,6 +151,8 @@ Laravel includes a variety of functions for manipulating string values. Many of
149151
[decrypt](#method-fluent-str-decrypt)
150152
[deduplicate](#method-fluent-str-deduplicate)
151153
[dirname](#method-fluent-str-dirname)
154+
[doesntEndWith](#method-fluent-str-doesnt-end-with)
155+
[doesntStartWith](#method-fluent-str-doesnt-start-with)
152156
[encrypt](#method-fluent-str-encrypt)
153157
[endsWith](#method-fluent-str-ends-with)
154158
[exactly](#method-fluent-str-exactly)
@@ -225,6 +229,8 @@ Laravel includes a variety of functions for manipulating string values. Many of
225229
[when](#method-fluent-str-when)
226230
[whenContains](#method-fluent-str-when-contains)
227231
[whenContainsAll](#method-fluent-str-when-contains-all)
232+
[whenDoesntEndWith](#method-fluent-str-when-doesnt-end-with)
233+
[whenDoesntStartWith](#method-fluent-str-when-doesnt-start-with)
228234
[whenEmpty](#method-fluent-str-when-empty)
229235
[whenNotEmpty](#method-fluent-str-when-not-empty)
230236
[whenStartsWith](#method-fluent-str-when-starts-with)
@@ -581,6 +587,54 @@ $result = Str::deduplicate('The---Laravel---Framework', '-');
581587
// The-Laravel-Framework
582588
```
583589

590+
<a name="method-doesnt-end-with"></a>
591+
#### `Str::doesntEndWith()` {.collection-method}
592+
593+
The `Str::doesntEndWith` method determines if the given string doesn't end with the given value:
594+
595+
```php
596+
use Illuminate\Support\Str;
597+
598+
$result = Str::doesntEndWith('This is my name', 'dog');
599+
600+
// true
601+
```
602+
603+
You may also pass an array of values to determine if the given string doesn't end with any of the values in the array:
604+
605+
```php
606+
use Illuminate\Support\Str;
607+
608+
$result = Str::doesntEndWith('This is my name', ['this', 'foo']);
609+
610+
// true
611+
612+
$result = Str::doesntEndWith('This is my name', ['name', 'foo']);
613+
614+
// false
615+
```
616+
617+
<a name="method-doesnt-start-with"></a>
618+
#### `Str::doesntStartWith()` {.collection-method}
619+
620+
The `Str::doesntStartWith` method determines if the given string doesn't begin with the given value:
621+
622+
```php
623+
use Illuminate\Support\Str;
624+
625+
$result = Str::doesntStartWith('This is my name', 'That');
626+
627+
// true
628+
```
629+
630+
If an array of possible values is passed, the `doesntStartWith` method will return `true` if the string doesn't begin with any of the given values:
631+
632+
```php
633+
$result = Str::doesntStartWith('This is my name', ['This', 'That', 'There']);
634+
635+
// true
636+
```
637+
584638
<a name="method-ends-with"></a>
585639
#### `Str::endsWith()` {.collection-method}
586640

@@ -2218,6 +2272,56 @@ $string = Str::of('/foo/bar/baz')->dirname(2);
22182272
// '/foo'
22192273
```
22202274

2275+
<a name="method-fluent-str-doesnt-end-with"></a>
2276+
#### `doesntEndWith` {.collection-method}
2277+
2278+
The `doesntEndWith` method determines if the given string doesn't end with the given value:
2279+
2280+
```php
2281+
use Illuminate\Support\Str;
2282+
2283+
$result = Str::of('This is my name')->doesntEndWith('dog');
2284+
2285+
// true
2286+
```
2287+
2288+
You may also pass an array of values to determine if the given string doesn't end with any of the values in the array:
2289+
2290+
```php
2291+
use Illuminate\Support\Str;
2292+
2293+
$result = Str::of('This is my name')->doesntEndWith(['this', 'foo']);
2294+
2295+
// true
2296+
2297+
$result = Str::of('This is my name')->doesntEndWith(['name', 'foo']);
2298+
2299+
// false
2300+
```
2301+
2302+
<a name="method-fluent-str-doesnt-start-with"></a>
2303+
#### `doesntStartWith` {.collection-method}
2304+
2305+
The `doesntStartWith` method determines if the given string doesn't begin with the given value:
2306+
2307+
```php
2308+
use Illuminate\Support\Str;
2309+
2310+
$result = Str::of('This is my name')->doesntStartWith('That');
2311+
2312+
// true
2313+
```
2314+
2315+
You may also pass an array of values to determine if the given string doesn't start with any of the values in the array:
2316+
2317+
```php
2318+
use Illuminate\Support\Str;
2319+
2320+
$result = Str::of('This is my name')->doesntStartWith(['This', 'That', 'There']);
2321+
2322+
// true
2323+
```
2324+
22212325
<a name="method-fluent-str-encrypt"></a>
22222326
#### `encrypt` {.collection-method}
22232327

@@ -3519,6 +3623,38 @@ $string = Str::of('tony stark')
35193623

35203624
If necessary, you may pass another closure as the third parameter to the `when` method. This closure will execute if the condition parameter evaluates to `false`.
35213625

3626+
<a name="method-fluent-str-when-doesnt-end-with"></a>
3627+
#### `whenDoesntEndWith` {.collection-method}
3628+
3629+
The `whenDoesntEndWith` method invokes the given closure if the string doesn't end with the given sub-string. The closure will receive the fluent string instance:
3630+
3631+
```php
3632+
use Illuminate\Support\Str;
3633+
use Illuminate\Support\Stringable;
3634+
3635+
$string = Str::of('disney world')->whenDoesntEndWith('land', function (Stringable $string) {
3636+
return $string->title();
3637+
});
3638+
3639+
// 'Disney World'
3640+
```
3641+
3642+
<a name="method-fluent-str-when-doesnt-start-with"></a>
3643+
#### `whenDoesntStartWith` {.collection-method}
3644+
3645+
The `whenDoesntStartWith` method invokes the given closure if the string doesn't start with the given sub-string. The closure will receive the fluent string instance:
3646+
3647+
```php
3648+
use Illuminate\Support\Str;
3649+
use Illuminate\Support\Stringable;
3650+
3651+
$string = Str::of('disney world')->whenDoesntStartWith('sea', function (Stringable $string) {
3652+
return $string->title();
3653+
});
3654+
3655+
// 'Disney World'
3656+
```
3657+
35223658
<a name="method-fluent-str-when-empty"></a>
35233659
#### `whenEmpty` {.collection-method}
35243660

0 commit comments

Comments
 (0)