Parsing a comma-delimited string into variables in a pattern

Jeff133
Giga Contributor

Possibly brain-fog, but I can't figure out how to parse a comma-delimited string variable value into multiple variables in a Service Mapping Pattern I'm writing. Here's what I mean:

I have a variable that contains a,b,c,d,e,f,g but I don't know how many letters there will be - maybe zero, maybe one, maybe many.

I want to end up with a table with a column called letters and a row for each letter.

Any ideas?

Note: actual values converted to letters to protect the data 😉

6 REPLIES 6

Jeff133
Giga Contributor

I tried this (below) based upon some script in the A10 Load Balancer Pattern...

In step 1, I get the comma-delimited string into a variable: $get_servers (a,b,c,d)

In step 2, I create an empty table: test_table

In step 3, I use Set Parameter Value with this script (below) as the Value and $test_table_tmp as the Name...

var rtrn = '';

var table = ${test_table};

var serverArray = ${get_servers}.split(",");

for(var i = 0; i < serverArray.length; i++){

    ${test_table}.add(serverArray[i]);

}

rtrn = table;

...but what I end up with is an empty $test_table and an array in $test_table_tmp ([a, b, c, d]).

Sundar16
Tera Contributor

Did you find/develop solution for this? I am also trying to do the same in pattern.