In my normal coding environment (PHP) I would do something like this:
$str = "foo bar baz";
echo $str . "\n"; // "foo bar baz\n"
$arr = explode(' ', $str);
$arr = array_map(fn($elem) => strtoupper($elem), $arr);
$str = implode(' ', $arr);
echo $str . "\n"; // "FOO BAR BAZ\n"
or even
$str = "foo bar baz";
echo $str . "\n"; // "foo bar baz\n"
$str = array_reduce(
explode(' ', $str),
fn($carry, $item) => $carry ? $carry . " " . strtoupper($item) : strtoupper($item),
''
);
echo $str . "\n"; // "FOO BAR BAZ\n"
If we don't get too fancy this basically does the following:
- loop over a collection and do something to every element of the collection
- assign the result of your work to the collection's item we're currently iterating over
- return the changed collection
I know KM has a for each action, but I can't seem to figure out how to do the same thing I did here: There is "lines in collection" or "substrings in collection" and I can let KM do some work on each of the elements, but how do I assign the result? And how do I return the changed collection?
Come to think of it: The nearest approximation of what I want would look like this in PHP:
$str = "foo bar baz";
echo $str . "\n";
$arr = explode(' ', $str);
foreach($arr as $key => $elem) {
$arr[$key] = strtoupper($elem);
}
$str = implode(' ', $arr);
echo $str . "\n";
I know how I could help myself in multiple ways (like running a script action), but can you do it with KM native tools?