Heber Solis
Heber Solis

Reputation: 493

how can I split this list?

I have a list that I get from reading an excel column, and I want to split it in individual values and format it like this 'value1', 'value2',...etc

this is the list value

$arrayElements: '["C1554718","C1553930","C1554247","C1554312","C1554357","C1554358","C1554359","C1554364","C1554365","C1554366","C1554367","C1554368","C1554369","C1554370","C1554371","C1554372","C1554373","C1554374","C1554375","C1554376","C1554377","C1554378","C1554379","C1554380","C1554381","C1554382","C1554383","C1554384","C1554385","C1554386","C1554387","C1554388","C1554389","C1554390","C1554391","C1554392","C1554393","C1554394","C1554395","C1554396","C1554397","C1554398","C1554399","C1554400","C1554401","C1554402"]'

this is my code:

$arraySplit=$arrayElements.split()
$list2= ($arraySplit| ForEach-Object { "'$_'" }) 

Upvotes: 0

Views: 48

Answers (1)

Daniel Manta
Daniel Manta

Reputation: 6683

Turn the string into a comma separated list and apply Split by comma.

$arraySplit= $arrayElements.Substring(1,$arrayElements.Length-2).Replace('"','').Split(",")

Upvotes: 1

Related Questions