How to Split string with Dash

How to Split string with Dash

Have Numbers field like 1-2-3-4

Would like to create new hidden Fields ie. Field1, Field2, Filed3, Field4 each containing data

Field1=1
Field2=2
Field3=3
Field4=4

Hey

can you try this example?

strResult.Split("-")

image

inside the for each you can assing each item to your variables, or else you can assing directly like this

Field1 = yourList(0)
Field2 = yourList(1)
etc...

image

Regards

1 Like

@broker

You can try this inassign

Newdict = str.Split({"-"},StringSplitOptions.None).ToDictionary(function(x) "Field"+x,function(x) x)

Hope this helps

Cheers

1 Like

@Anil_G - Wonderful answer , that should work.

@broker - In case don’t want to create dictionary,

  1. Create four variables named “Field1”, “Field2”, “Field3”, and “Field4”.
  2. Use the “Assign” activity to assign the string value “1-2-3-4” to a variable named “numbers”.
  3. Use the “Split” function to split the string into an array of substrings, using the dash character (“-”) as the separator. Assign the result to a new variable named “numberArray”. The expression would be: numbers.Split("-"c)
  4. Use the “Assign” activity to create a LINQ query that creates an array of the four fields, using the “Select” function to transform each element of the “numberArray” into a new variable. The expression would be:

{ "Field1", "Field2", "Field3", "Field4" }.Zip(numberArray, Function(f, n) n).ToArray()

This expression first creates an array of the four field names, then uses the “Zip” function to combine each element of the field name array with each element of the “numberArray”, and finally uses the “Select” function to transform each combined element into a new variable.

  1. Use the “Assign” activity to assign the first element of the resulting array to the “Field1” variable. The expression would be: result(0)
  2. Use the “Assign” activity to assign the second element of the resulting array to the “Field2” variable. The expression would be: result(1)
  3. Use the “Assign” activity to assign the third element of the resulting array to the “Field3” variable. The expression would be: result(2)
  4. Use the “Assign” activity to assign the fourth element of the resulting array to the “Field4” variable. The expression would be: result(3)
1 Like