Edit 2022: storeEval is deprecated. Now use executeScript_Sandbox to split strings.
I use the Javascript “split” function and storeEval
to get an unlimited number of command line variables.
- You send the values as one long string via
cmd_var1=hello%21world***123***it%21works
- Inside the macro you split the string at
***
and assign each part to a separate variable - That is all
Test macro: It splits the string in five parts and assigns it to s1, s2… and s5. Instead of the variable ${s}
you would actually use ${!cmd_var1}
:
{
"Name": "split",
"CreationDate": "2023-3-12",
"Commands": [
{
"Command": "store",
"Target": "This is parameter1***Hi, I am parameter2***I am No3***I am No4***I am No5",
"Value": "s",
"Description": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "var str = ${s}; var res = str.split(\"***\"); return res[0]",
"Value": "s1",
"Description": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "var str = ${s}; var res = str.split(\"***\"); return res[1]",
"Value": "s2",
"Description": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "var str = ${s}; var res = str.split(\"***\"); return res[2]",
"Value": "s3",
"Description": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "var str = ${s}; var res = str.split(\"***\"); return res[3]",
"Value": "s4",
"Description": ""
},
{
"Command": "executeScript_Sandbox",
"Target": "var str = ${s}; var res = str.split(\"***\"); return res[4]",
"Value": "s5",
"Description": ""
},
{
"Command": "echo",
"Target": "Command line var1=${s1}",
"Value": "green",
"Description": ""
},
{
"Command": "echo",
"Target": "Command line var2=${s2}",
"Value": "blue",
"Description": ""
},
{
"Command": "echo",
"Target": "Command line var3=${s3}",
"Value": "green",
"Description": ""
},
{
"Command": "echo",
"Target": "Command line var4=${s4}",
"Value": "blue",
"Description": ""
},
{
"Command": "echo",
"Target": "Command line var5=${s5}",
"Value": "green",
"Description": ""
}
]
}
PS: If you have many variable, consider using an array instead of s1…sX