Spliting an input

Hey,

Probably has been asked a lot of times, but lets say I want someone to input several numbers delimited by space or , using only one input dialog instead of multiple ones. How would I achieve splitting these numbers into an array since the .Split is only available to strings and I cannot simply use assign since the = doesnt work for strings. Basically I want one input dialog where they enter multiple numbers separated by space, then I want them split into an array of integers so I can do whatever i want with the numbers like multiplying them or whatever. Im assuming convering them would work but how would I convert the strings to numbers since I cannot split them in the first place?

Hi @xdrftww

=> Use Input Dialog Activity

Dialog Title: "Enter Numbers"
Input Label: "Please enter numbers separated by space or comma:"
Input Type: Text Box
Value Entered: userInput(Output variable)(DataType: System.String)

=> Use below syntax in Assign activity:

stringArray = userInput.Split({" "c, ","c}, StringSplitOptions.RemoveEmptyEntries)

stringArray is of DataType Array(System.String)

=> Use below syntax in Assign activity:

intArray = stringArray.Select(Function(x) Convert.ToInt32(x)).ToArray()

intArray is of DataType Array(System.Int32)

Regards

1 Like

@xdrftww

Welcome to the community

You can try below

Say the output from input dialog is str

Then use assign

RequiredintArrat = str.Split(" "c).Select(function(x) Cint(x)).ToArray

Hope this helps

Cheers

1 Like

Thank you both I realized my stupid mistake. I was writing in the Value to save the entire assign like this intArray = stringArray.Select(Function(x) Convert.ToInt32(x)).ToArray() instead of just stringArray.Select(Function(x) Convert.ToInt32(x)).ToArray().

:slight_smile:

2 Likes

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