Array With Delimiter From Variable

Hi!

Is there any way to count (or set or read) a variable array, with a custom delimiter defined from a variable?

I thought I had testen (and succeeded in) this before, but when searching my macros now I can't find any example of it, so I must have imagined it.

Setting it up as %Variable%local_array[0]local_delimiter% does not work, as it is local_delimiter (not the content of the variable) that is interpreted as the delimiter ('correctly' returning 1 as the result ).

Setting it up as %Variable%local_array[0]%Variable%local_delimiter%% also does not work, as it gets interpreted as %Variable%local_array[0]% followed by Variable followed by %local_delimiter% followed by % ('correctly' returning a result of 1Variable;% (took me a while to wrap my head around what was going on with this one!)).

Anyone having any idea of how/if this can be done?

Calculate Array Size Based of Custom Delimiter from Variable.kmmacros (2.9 KB) (v11.0.2)

Try this:

1 Like

This works! Thank you so much!

I had the feeling a Filter action to Process Tokens could be part of the solution, but I am never fully able to grasp the logic of where and when it's needed.

Something else I am not able to fully grasp is how you've divided out the percentage symbols to make this work. The way I am reading it out is like this:

Trying to make logic

Edit: The logic in my image bellow is slightly flawed. (If I've now managed to understand it better) the %%Variable%local_array[0]%local_delimiter%% first resolves as %Variable%local_array[0]:% (when the variable local_delimiter is set to ":"), and after second process of the token (performed by the filter action) it is returning the content of the variable local_array[0]: — returning a "5", the number of array elements in the variable local_array (delimited by the ":").

But I know this must be wrong as the extra % makes no sense (and it does not work without it). In the interest of learning I'd love to hear your logic behind how this is set up @kcwhat, and also if you have any thought about when and where the Filter action to Process Tokens is needed. Also if anyone else kan shed light on this, I am more than interested in any thoughts!

You're welcome. Glad it worked and I'm sure there are other ways to solve it. I had a similar situation and 2 posts, from @peternlewis, helped me. I bookmarked them for future reference. Both are from the same topic/thread and I'm sure I read them 20 times. Some days I understood and some I didn't. Today, I did and tomorrow I won't. :slight_smile:

In any event, bookmark the below:

Take care,
KC

1 Like

Those posts are now bookmarked, and I'll go through them carefully tomorrow, after a nights sleep as I quickly felt it not sinking in past my tired eyes here right now. But I think Peters defining it as the Filter action processes the tokens a second time, whats left of the tokens after the first time that is, can be the key for me to make logic of this! Thank you so much for pointing me to this!

1 Like

I thought I had gotten a slight hang of dynamic variables, but once again I've found myself struggling in making coherent logic of it — this time with setting a variable array element, with custom delimiter dynamically set from variable.

Does anyone know if what I am attempting here is possible, or where in my approaches bellow I am leading myself astray:

Set variable array with dynamically set index and custom delimiter .kmmacros (14 KB)
(v11.0.2)

Macro Image

Macro image with expanded groups for approaches 1 and 3


Approach 1 in the macro above is based off of the approach @kcwhat pointed me towards earlier in this thread. It works for counting array size (as demonstrated in attached macro bellow), but I am not able to get this approach working for setting an array element.

Calculate array size based of custom delimiter from variable Macro

Calculate array size based of custom delimiter from variable.kmmacros (2.9 KB)
(v11.0.2)

Macro Image

I had grossly overthought and overcomplicated the task at hand – No Filter to Process Tokens or doubling of parenthesise needed – And I now got it working!

DEMONSTRATION — How to set a variable array element- with index and custom delimiter both set from variables (v1.0.1).kmmacros (3.6 KB)
(v11.0.2)



EDIT: Realised that for it to work with a custom delimiter set to the newline character \n the variable holding this delimiter needs to be set to not process tokens. I therefore uploaded a new version of the demonstration above set up in this way.

How to set variable not to process tokens