Skip to content

Commit d9ddec5

Browse files
committed
add more Str methods
1 parent 5192fbb commit d9ddec5

1 file changed

Lines changed: 57 additions & 1 deletion

File tree

v5/utilities.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,26 @@ Str::contains('it', 'Name it!');
466466
// true
467467
```
468468

469+
### Str::makeWords
470+
471+
The `Str::makeWords()` method replaces a delimiter with a space, `' '`, in given string with the option to title case the result.
472+
473+
```php
474+
use \TypeRocket\Utility\Str;
475+
476+
Str::makeWords('foo_bar', false);
477+
// foo bar
478+
479+
Str::makeWords('foo_bar', true);
480+
// Foo Bar
481+
482+
Str::makeWords('foo-bar', true, '-');
483+
// Foo Bar
484+
```
485+
469486
### Str::notBlank
470487

471-
Use the method `Str::notBlank()` to check if a value is `null` or an empty string.
488+
The `Str::notBlank()` method checks if a value is `null` or an empty string.
472489

473490
```php
474491
use \TypeRocket\Utility\Str;
@@ -486,6 +503,28 @@ Str::notBlank(' ');
486503
// true
487504
```
488505

506+
### Str::pregMatchFindFirst
507+
508+
The `Str::pregMatchFindFirst()` method returns the first regex pattern to match a given string. However, the regex applies `#` vs `/` as the delimiters:
509+
510+
```php
511+
use \TypeRocket\Utility\Str;
512+
513+
// Do not use delimiters at the
514+
// start and end of patterns.
515+
$patters = [
516+
'[a-z]+',
517+
'brother',
518+
'dad',
519+
'mom'
520+
];
521+
522+
$subject = 'dad';
523+
524+
Str::pregMatchFindFirst($patters, $subject);
525+
// '[a-z]+'
526+
```
527+
489528
### Str::replaceFirst
490529

491530
The `Str::replaceFirst()` method replaces the first occurrence of a given value in the string:
@@ -544,6 +583,23 @@ Str::replaceLast($replace, $with, $string);
544583
// 'momster po'
545584
```
546585

586+
### Str::splitAt
587+
588+
The `Str::splitAt()` method splits at a delimiter string into two parts:
589+
590+
```php
591+
use \TypeRocket\Utility\Str;
592+
593+
Str::splitAt('foo.bar.baz');
594+
// ['foo', 'bar.baz']
595+
596+
Str::splitAt('.', 'fooBar');
597+
// ['fooBar', null]
598+
599+
Str::splitAt('.', 'fooBar', true);
600+
// ['foo.bar', 'baz']
601+
```
602+
547603
### Str::snake
548604

549605
The `Str::snake()` method converts a string to snake case.

0 commit comments

Comments
 (0)