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

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,


Just an example taken from Network Switch Pattern like below:

 

Thanks,

Ashutosh

Hi Ashutosh, I don't think that will work for my needs as the SNMP query reads from finite locations. What I need is something along the lines of...

  1. Create a table
  2. Parse the comma-delimited variable value
  3. Write the parsed values into rows in the table

Brad Bowman
Kilo Patron
Kilo Patron

I would create an array of the comma-delimited variable values, something like 

var myArr = variablename.split(',');

You can then reference each element via 

myArr[0]; //where 0 is the index number of the element

or loop through the array like so

for(var i=0; i<myArr.length; i++){
//do something with myArr[i];
}

Hi Brad, That's exactly what I had in mind, but I also need to create a table and push the values into it as rows. In reality, each letter is a server that I want to make a connection to. I figure if I can put them into a table, I can create connections row by row...

host   $theTable[*].server

port    $theTable[*].port

I can't figure out how in a Pattern to create a table and pass the array values from inside the for loop in the script.