Page 1 of 1
Creating unique string variables from a list
Posted: 05 May 2020 15:49
by skiptannen
I can't find a solution in the forum and I can't figure out how to write the script - I simply want to create unique variables for each string value in a list. For example, for the following list:
Code: Select all
list=newList("one","two","three");
I would like to end up with the following variables:
var_string_1 = "one"
var_string_2 = "two"
var_string_3 = "three"
I'm sure this is simple with the correct script syntax but it's escaping me...
Thanks in advance.
Re: Creating unique string variables from a list
Posted: 05 May 2020 17:39
by Desmanto
use setValue() to create new variable name from list/map.
There are several ways. Below are 2 examples
Code: Select all
list = newList("one","two","three");
for(i in list)
setValue(i, i); //one = "one"
for(i in [0 to length(list)-1])
setValue("var_string_{i+1}" , list[i]); //var_string_1 = "one"
Assuming your list contains unique element and conform to variabel naming pattern, then you can use the first method to create variable name directly from the content. But it won't work if you have duplicates or the string is something not variable-name friendly.
Second method is to use the index and add 1, then concat it to prefix var_string_ This create uniform numbered variable from the list. It works with duplicate and the result of the variable also has the same order as the list.
Re: Creating unique string variables from a list
Posted: 05 May 2020 20:04
by skiptannen
That's perfect - thanks so much Desmanto. I really appreciate the example and the explanations. I can now get the flow working and I have a much better understanding.
Cheers!