Split a string by a comma into n equal parts

Below is the example

Example
a,b,c,d,e,f

Output

Part1 - a,b,c
Part2 - d,e,f

Thanks

we do have more options for this. Some more details can help for selecting one choice out of many

In the mean while a quick/dirty simple one:
grafik

And when we have this length of not length is a multiple of 2:
grafik

thats why we used the \ for the integer division

1 Like

Any idea , how we can have n equal parts .

With the above solution it is giving 2 parts

Hi @Hitesh1 ,

I believe we need more details for this to be concluded.

From your Input String and Output Requirement, we have the Below Two Possible Outputs :

Output 1 = {"a,b","c,d","e,f"}

Output 2 = {"a,b,c","d,e,f"}

Would You explain as to what is the Output that is required for your case and Why so as to use the Logic.

1 Like

If number of the words in string is greater than 200 then we may need 3 equal parts and if no. of words< 200 words then 2 equal parts

I have to make decision based on words of string

Hi @Hitesh1 ,

Could you give this workflow a try?

Enumerable.Range(0,CInt(arr_items.Count()/int_itemCount)).Select(Function(s) arr_items.Skip(s*int_itemCount).Take(int_itemCount).ToArray).ToArray

I’ve added both examples, so don’t get confused between the more and less keywords, its the same code but with both scenarios.

SplitArrayIntoSizableUnits.xaml (8.4 KB)

Kind Regards,
Ashwin A.K

Hi Hitesh,

You can you skip and take functions as per your requirement.

Please check below xaml file
stringFormat.xaml (7.1 KB)

Thank you,
Debakanta.

Sorry, but I am not able to get where to pass my string having n number of words

Hi @Hitesh1 ,

Yep, I overcomplicated it, my mistake!

image

Here is a simpler workflow β†’

SplitArrayIntoSizableUnits_v1.xaml (6.2 KB)

Kind Regards,
Ashwin A.K

Thanks for answer. I tested this for 6 words , it is not working as expected

input {β€œa”,β€œb”,β€œc”,β€œd”,β€œe”,β€œf”}
If(arr_items.Count>5,3,2) – It should create 3 parts a,b c,d and e,f

input {β€œa”,β€œb”,β€œc”,β€œd”}
If(arr_items.Count>5,3,2) – It should create 2 parts a,b,c and d,e,f

Hi @Hitesh1 ,

let me give an example what is your input and expected output.

Regards,
Arivu

Hi @Hitesh1 ,

Could you verify once more?
For six item array β†’

image
For five item array β†’
image

The last item is getting omitted, but that can be fixed using a Math.Celing function like so β†’

Enumerable.Range(0,Cint(Math.Ceiling(arr_items.Count()/int_itemCount))).Select(Function(s) arr_items.Skip(s*int_itemCount).Take(int_itemCount).ToArray).ToArray

image

SplitArrayIntoSizableUnits_v2.xaml (7.9 KB)

Kind Regards,
Ashwin A.K