Is it possible to split the number, provide calculation and join it again?
I have a hours:minutes:seconds:frames format but need only hours to be changed.
1595800-2595800 etc.
Thanks!
Is it possible to split the number, provide calculation and join it again?
I have a hours:minutes:seconds:frames format but need only hours to be changed.
1595800-2595800 etc.
Thanks!
Yes.
Oh, you want more?
You put everything up to the first :
into a variable, do a calculation on that variable, replace everything up to the first :
in your original string with the new value:
Hours Replace v10.kmmacros (4.2 KB)
(That deliberately uses different ways of defining the hours
string -- pseudo array for the "get", a \d+
regex for the "set" -- to show different options.)
If you are on KM v11 you can make use of the new functionality of setting a pseudo array value, saving a couple of actions and maintaining consistency between the "get" and "set" actions:
Hours Replace v11.kmmacros (3.7 KB)
It's a shame your string isn't ,
delimited -- if it was you could (in v11) do the getting, calculation, and setting all in one action:
Hours Replace v11 Calc.kmmacros (3.4 KB)
...but, unfortunately, you can't use arbitrary pseudo array delimiters in Calculation actions/tokens. You could search-and-replace :
for ,
, use the same Calculation action, then search-and-replace ,
for :
-- but that's just making things less efficient again.
Thanks!
I have a few quiestions though:
Sorry for silly quiestions! I am not a pro in KM.
You didn't provide the "original text" you wanted to split. I made something up based on your description of the format and missed out a value by accident. It doesn't matter though -- because you want the "hours" value it will always be the first item of the string (everything up to the first :
), however many other items there are.
You are already using it with a :
so there's no need to change except for the last example, and that's a KM v11-only macro.
They aren't silly questions -- always ask if the examples aren't clear. But they are only short examples -- take a moment to look at them action by action while referring to the KM Manual and the Wiki.
You'll soon see that these are sequences of otherwise simple actions -- the trick is knowing which action to use when and the options available, and that'll come with practice.
Thanks! I am really trying to understand what I do what I do when I use the help from this forum (except scripts :-))
EDIT: Sorry I have found it in the first reply!
About the V11 macro:
When I add [1] to the variable name, what does it do? Use the values before the first delimiter? How can tell the macro that delimiter is ":"?
To the manual! Specifically Using Variables and its "Variable Arrays" section.
So yes, [1]
is "the first item in the array" ([2]
is the second, etc). By default the item delimiter is ,
so the text a,b,c,d
is an array containing 4 items and item 1 is a
.
But you can also tell KM to use a different delimiter by putting it immediately after the ]
-- so [1]:
is "the first item of the array delimited by :
and using it with the text w:x:y:z
would get us w
.
You aren't limited to a single character as the delimiter, you can also use a string. So [2]Fish
used on AliceFishBobFishCharles
would get us Bob
.
The above is for text variables. Calculations can't include custom delimiters and only use the default ,
-- but are very useful because things like window dimensions are comma-delimited lists.
I am sorry, I have to read the whole manual.
The problem is solved! The whole macro now works as expected using your method!
Thanks a lot!