Complicated string split to more conditional array

String= America-US;Switzerland-CH;Macao-MO;New Zealand-NZ;Japan-JP

How I get
arr1= {America, Switzerland,Macao,New Zealand,Japan}
arr2= {US,CH,MO,NZ;JP}
split keyword is ; and -

strinput.Split(";"c).ToArray.select(Function(a) a.split("-"c).first).toarray
strinput.Split(";"c).ToArray.select(Function(a) a.split("-"c).last).toarray
1 Like

Maybe there’s a quick and clean linq solution for this, but sticking to more classic assigns and activities:

  • splt the array based on the ;. Lets call that arr0
  • count the number of items in arr0
  • define arr1 and arr2 with the size / count of arr0
  • loop through each item in arr0, and split each member on -
  • assign the first value to arr1, the 2nd to arr2

one of more options, which can also be adapted:

1 Like

This is good idea for Dictionary !! Thankyou

It’s worked. Thank you!!

1 Like

@scorpialee

Cheers, Happy automation!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.