Extracting a variable number of values from a string

Hi all

I get some data which I manipulate in to a string variable. The data contains up to 20 numbers (in reality these are monetary values) separated by a comma, which can change each time I get a new item from the queue. For example, the string could be 678, 635, 632, 785 then for the next queue item it could be 6746, 57574

Each time I work an item from the queue, I need to split these values (by using the comma) and then put them in to individual variables named accordingly as ‘monetary value 1’ monetary value 2’ and so on. I also need to count how many monetary values I have worked with, as I will need this value later on in the process.

Please can I ask you all for the best way to achieve this?

Thanks for the help,

why do you need them in seperate variables?
after you split the string you have a array of strings

you could get the .Length of this array
you could also loop trough this array and use it slitArray(counter) to get the values

1 Like

There are two methods that quickly come to mind that will do what you need.

What you have is not just comma delineated, it includes a space. Your separator in that case is ", ". In order to get that out, you’ll likely use the String.Split method but do so using one of the overrides with the StringSplitOptions items, please see below.

The second method would be to use Regular Expressions to grab out all of the numbers. Since you care about digits only (so no floating points with decimals), then \d+ will work fine in this case, please see below.

Test_SplitByComma.xaml (5.8 KB)

1 Like

Thanks for the xaml - makes perfect sense :slight_smile: For the moment, I’ve got a flow switch inside a for each where I assign the values individually from the array I’ve created of up to 20 numbers. I will move on to using regex though when I can; a much cleaner and quicker method by the looks of things here.


1 Like

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