add string replace

This commit is contained in:
Pekka Laiho 2020-06-04 09:27:09 +07:00
parent b568ece8f0
commit 42441e78c2

View File

@ -17,7 +17,7 @@ class Strings implements ILib
fn (string $a) => strtoupper($a) fn (string $a) => strtoupper($a)
)); ));
$env->set('locase', new CoreFunc('locase', 'Return string in lower case.', 1, 1, $env->set('lowcase', new CoreFunc('lowcase', 'Return string in lower case.', 1, 1,
fn (string $a) => strtolower($a) fn (string $a) => strtolower($a)
)); ));
@ -31,6 +31,10 @@ class Strings implements ILib
} }
)); ));
$env->set('replace', new CoreFunc('replace', 'Change occurrences in first argument from second argument to third argument.', 3, 3,
fn (string $a, string $b, string $c) => str_replace($b, $c, $a)
));
$env->set('split', new CoreFunc('split', 'Split the second argument by the first argument into a list.', 2, 2, $env->set('split', new CoreFunc('split', 'Split the second argument by the first argument into a list.', 2, 2,
fn (string $a, string $b) => new MList(explode($a, $b)) fn (string $a, string $b) => new MList(explode($a, $b))
)); ));