dmasior / string-builder
This package is abandoned and no longer maintained.
No replacement package was suggested.
StringBuilder for PHP
2.0.1
2020-05-26 21:06 UTC
Requires
- php: ^7.2
Requires (Dev)
- phpstan/phpstan: ^0.12.25
- phpunit/phpunit: ^8.0
- slevomat/coding-standard: ^6.3
- squizlabs/php_codesniffer: ^3.5
Suggests
- ext-mbstring: *
README
Mutations over sequence of characters.
✔️ Requirements
- PHP 7.2+
Suggestions
- ext-mbstring for multibyte support
Installation
$ composer require dmasior/string-builder
⌨️ Usage
Instantiation
use Dmasior\StringBuilder\Builder; // Via new $builder = new Builder('Hi!'); // Via create method $builder = Builder::create('Hi!');
Append
$builder->append('Hello') ->append(' world'); $builder->toString(); // "Hello world"
Insert
$builder->insert(0, 'Hello') ->insert(5, ' world'); $builder->toString(); // "Hello world"
Delete
$builder->append('1234567') ->delete(5, 7); $builder->toString(); // "1234"
DeleteCharAt
$builder->append('12345') ->deleteCharAt(5); $builder->toString(); // "1234"
IndexOf
$builder->append('123abc123abc'); $builder->indexOf('123'); // 0
LastIndexOf
$builder->append('123abc123abc'); $builder->lastIndexOf('123'); // 6
Reverse
$builder->append('4321') ->reverse() ->toString(); // "1234"
Length
$builder->append('1234') ->length(); // 4
Substring
$builder->append('012345') ->substring(1, 3); // "123"
CharAt
$builder->append('123') ->charAt(1); // "2"