Add new split string, update split string format, add create string from array list, char in char list, remove duplicates
NEW: - remove duplicates in string - check character string list in other character string list - build character string from array (or nested array) values - split string with fixed split length UPDATE: - split string with format * throw exceptions for wrong paramters * remove the "split chracters", as they get extracted from the format string
This commit is contained in:
@@ -14,6 +14,9 @@ require 'config.php';
|
||||
$LOG_FILE_ID = 'classTest-string';
|
||||
ob_end_flush();
|
||||
|
||||
use CoreLibs\Convert\Strings;
|
||||
use CoreLibs\Debug\Support as DgS;
|
||||
|
||||
$log = new CoreLibs\Logging\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
'log_file_id' => $LOG_FILE_ID,
|
||||
@@ -29,6 +32,7 @@ print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$split = '4-4-4';
|
||||
$split_length = 4;
|
||||
$test_strings = [
|
||||
'13',
|
||||
'1234',
|
||||
@@ -40,20 +44,59 @@ $test_strings = [
|
||||
];
|
||||
|
||||
foreach ($test_strings as $string) {
|
||||
print "Convert: $string with $split to: "
|
||||
. \CoreLibs\Convert\Strings::splitFormatString($string, $split)
|
||||
print "A) Convert: $string with $split to: "
|
||||
. Strings::splitFormatString($string, $split)
|
||||
. "<br>";
|
||||
try {
|
||||
print "B) Convert: $string with $split_length to: "
|
||||
. Strings::splitFormatStringFixed($string, $split_length)
|
||||
. "<br>";
|
||||
} catch (Exception $e) {
|
||||
print "Split not possible: " . $e->getMessage() . "<br>";
|
||||
}
|
||||
}
|
||||
|
||||
$split = '2_2';
|
||||
$split_length = 2;
|
||||
$string = '1234';
|
||||
print "Convert: $string with $split to: "
|
||||
. \CoreLibs\Convert\Strings::splitFormatString($string, $split)
|
||||
print "A) Convert: $string with $split to: "
|
||||
. Strings::splitFormatString($string, $split)
|
||||
. "<br>";
|
||||
print "B) Convert: $string with $split_length to: "
|
||||
. Strings::splitFormatStringFixed($string, $split_length, "_")
|
||||
. "<br>";
|
||||
$split = '2-2';
|
||||
$string = 'あいうえ';
|
||||
print "Convert: $string with $split to: "
|
||||
. \CoreLibs\Convert\Strings::splitFormatString($string, $split)
|
||||
try {
|
||||
print "Convert: $string with $split to: "
|
||||
. Strings::splitFormatString($string, $split)
|
||||
. "<br>";
|
||||
} catch (\Exception $e) {
|
||||
print "Cannot split string: " . $e->getMessage() . "<br>";
|
||||
}
|
||||
print "B) Convert: $string with $split_length to: "
|
||||
. Strings::splitFormatStringFixed($string, $split_length, "-")
|
||||
. "<br>";
|
||||
|
||||
$string = 'ABCD12345568ABC13';
|
||||
$format = '2-4_5-2#4';
|
||||
$output = 'AB-CD12_34556-8A#BC13';
|
||||
print "A) Convert: $string with $format to: "
|
||||
. Strings::splitFormatString($string, $format)
|
||||
. "<br>";
|
||||
|
||||
// try other split calls
|
||||
$string = "ABCDE";
|
||||
$split_length = 2;
|
||||
$split_char = "-=-";
|
||||
print "Convert: $string with $split_length / $split_char to: "
|
||||
. Strings::splitFormatStringFixed($string, $split_length, $split_char)
|
||||
. "<br>";
|
||||
$string = "あいうえお";
|
||||
$split_length = 2;
|
||||
$split_char = "-=-";
|
||||
print "Convert: $string with $split_length / $split_char to: "
|
||||
. Strings::splitFormatStringFixed($string, $split_length, $split_char)
|
||||
. "<br>";
|
||||
|
||||
$test_splits = [
|
||||
@@ -63,9 +106,27 @@ $test_splits = [
|
||||
'2-3-4',
|
||||
];
|
||||
foreach ($test_splits as $split) {
|
||||
print "$split with count: " . \CoreLibs\Convert\Strings::countSplitParts($split) . "<br>";
|
||||
print "$split with count: " . Strings::countSplitParts($split) . "<br>";
|
||||
}
|
||||
|
||||
// check char list in list
|
||||
$needle = "abc";
|
||||
$haystack = "abcdefg";
|
||||
print "Needle: " . $needle . ", Haysteck: " . $haystack . ": "
|
||||
. DgS::prBl(Strings::allCharsInSet($needle, $haystack)) . "<br>";
|
||||
$needle = "abcz";
|
||||
print "Needle: " . $needle . ", Haysteck: " . $haystack . ": "
|
||||
. DgS::prBl(Strings::allCharsInSet($needle, $haystack)) . "<br>";
|
||||
|
||||
print "Combined strings A: "
|
||||
. Strings::buildCharStringFromLists(['A', 'B', 'C'], ['0', '1', '2']) . "<br>";
|
||||
print "Combined strings B: "
|
||||
. Strings::buildCharStringFromLists([['F'], ['G'], 'H'], [['5', ['6']], ['0'], '1', '2']) . "<br>";
|
||||
|
||||
$input_string = "AaBbCc";
|
||||
print "Unique: " . Strings::removeDuplicates($input_string) . "<br>";
|
||||
print "Unique: " . Strings::removeDuplicates(strtolower($input_string)) . "<br>";
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
// __END__
|
||||
|
||||
Reference in New Issue
Block a user