Dynamically load array with variable value not as string

July 27, 2020 at 19:22:57
Specs: Windows
I have a param variable which is dynamic ie.it can have N number of values delimited by spaces.As an example the below param has two values.But it can 3 or 4 values delimted by space.each key value pair will be separated by &.This is basically the syntax of tabcmd get.

SET PARAM=productname=%%a&productid=%%b empid=%%a&empname=%%b&empad=%%c ...
My requirement is to parse param not as string and load each of the values that are delimited by space into an array.Please note that array indexing should be dynamic since the number of parameters in param is dynamic.So in the above case there will be two array index, a[0]=productname=%%a&productid=%%b a[1]=empid=%%a&empname=%%b&empad=%%c

There can be a[3] or a[4] based on the number of parameter values. So the index should be dynamic.

Once the array is ready, I will feeding this inside a for loop which reads a file having the actual values for the variables mentioned in the param(product name,productid in the first iteration and emp details in the second iteration since we have only two values in this case).So there %%a, %%b, %%c should get replaced with the read actual values.

Why I mentioned not as a string is that if we parse param as a string then the %%a, %%b values wont get replaced with actual values from file. I tired to read param in for loop without adding quotes then an error is throwing & was not expecting at this time

Can someone provide suggestions to load the array dynamically without considering the param as string and the array index should be dynamic.

TIA


See More: Dynamically load array with variable value not as string

Related Solutions


Ask Question