Skip to content

Commit 1b34a75

Browse files
committed
add many Str methods
1 parent d508af4 commit 1b34a75

1 file changed

Lines changed: 102 additions & 1 deletion

File tree

v5/utilities.md

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,17 @@ Str::contains('it', 'Name it!');
569569
// true
570570
```
571571

572+
### Str::encoding
573+
574+
The `Str::encoding()` method gets the current internal PHP multibyte encoding:
575+
576+
```php
577+
use \TypeRocket\Utility\Str;
578+
579+
Str::encoding();
580+
// 'UTF-8'
581+
```
582+
572583
### Str::ends
573584

574585
The `Str::ends()` method tests if a string ends with a value:
@@ -591,6 +602,34 @@ Str::contains('it', 'Name it!');
591602
// true
592603
```
593604

605+
### Str::limit
606+
607+
The `Str::limit()` method limits a string to a specific number of characters starting from the left:
608+
609+
```php
610+
use \TypeRocket\Utility\Str;
611+
612+
Str::limit('Hello world!', 5);
613+
// 'Hello'
614+
615+
Str::limit('Hello world!', 5, '...');
616+
// 'Hello...'
617+
```
618+
619+
### Str::lower
620+
621+
The `Str::lower()` method converts a string to lowercase:
622+
623+
```php
624+
use \TypeRocket\Utility\Str;
625+
626+
Str::lower('ABC');
627+
// 'abc'
628+
629+
Str::lower('Ÿ');
630+
// 'ÿ'
631+
```
632+
594633
### Str::makeWords
595634

596635
The `Str::makeWords()` method replaces a delimiter with a space, `' '`, in given string with the option to title case the result.
@@ -608,9 +647,37 @@ Str::makeWords('foo-bar', true, '-');
608647
// Foo Bar
609648
```
610649

650+
### Str::maxed
651+
652+
The `Str::maxed()` method tests if a string's length past a maximum number of characters:
653+
654+
```php
655+
use \TypeRocket\Utility\Str;
656+
657+
Str::maxed('foo', 3);
658+
// false
659+
660+
Str::maxed('bar', 2);
661+
// true
662+
```
663+
664+
### Str:min
665+
666+
The `Str::min()` method tests if a string's length is a minimum number of characters:
667+
668+
```php
669+
use \TypeRocket\Utility\Str;
670+
671+
Str::min('foo', 3);
672+
// true
673+
674+
Str::min('bar', 4);
675+
// false
676+
```
677+
611678
### Str::notBlank
612679

613-
The `Str::notBlank()` method checks if a value is `null` or an empty string.
680+
The `Str::notBlank()` method checks if a value is `null` or an empty string:
614681

615682
```php
616683
use \TypeRocket\Utility\Str;
@@ -650,6 +717,26 @@ Str::pregMatchFindFirst($patters, $subject);
650717
// '[a-z]+'
651718
```
652719

720+
### Str::quiet
721+
722+
The `Str::quiet()` method checks if a value is `null` or a string that is blank when trimmed:
723+
724+
```php
725+
use \TypeRocket\Utility\Str;
726+
727+
Str::quiet('');
728+
// false
729+
730+
Str::quiet(' ');
731+
// true
732+
733+
Str::quiet(null);
734+
// true
735+
736+
Str::quiet(0);
737+
// false
738+
```
739+
653740
### Str::replaceFirst
654741

655742
The `Str::replaceFirst()` method replaces the first occurrence of a given value in the string:
@@ -708,6 +795,20 @@ Str::replaceLast($replace, $with, $string);
708795
// 'momster po'
709796
```
710797

798+
### Str::reverse
799+
800+
The `Str::reverse()` method reverses a given string:
801+
802+
```php
803+
use \TypeRocket\Utility\Str;
804+
805+
Str::reverse('abc');
806+
// 'cba'
807+
808+
Str::reverse("xŸz");
809+
// 'zŸx'
810+
```
811+
711812
### Str::splitAt
712813

713814
The `Str::splitAt()` method splits at a delimiter string into two parts:

0 commit comments

Comments
 (0)