Splitting a number in to Sections

Hi

Split any number into sections of 200 ie

9638 would become

1-200,201-400,401-600 etc etc to 9601-9638

and save sections in an array

@rmorgan

Assign: startValue = 1
Assign: sections = New List(Of String)

For (startValue <= 9638)
Assign: endValue = startValue + 199
Assign: section = startValue.ToString + “-” + endValue.ToString
Add to collection: sections, section
Assign: startValue = endValue + 1

If (endValue < 9638)
Assign: section = (endValue + 1).ToString + “-” + 9638.ToString
Add to collection: sections, section

Hi @rmorgan

Please find the below workflow file . Hope it helps meet your requirement.

  1. Assign → inputNumber = 9638
  2. Assign → startNumber = 1
  3. Assign → endNumber = 200
  4. Assign → numberSections = New List(Of Integer)
  5. While → startNumber <= inputNumber
    • Assign → section = startIndex.ToString + “-” + Math.Min(endIndex, inputNumber).ToString
    • Add To Collection → Collection: numberSections, Item: section
    • Assign → startNumber = endNumber + 1
    • Assign → endNumber = endNumber + 200
  6. If → startNumber <= inputNumber
    • Assign → lastSection = startNumber.ToString + “-” + inputNumber.ToString
    • Add To Collection → Collection: numberSections, Item: lastSection

Sequence20.xaml (13.6 KB)

Hope it helps!!

When project is set to Windows we can do:

mySegements | List(Of String) =

Enumerable.Range(1,9638).Chunk(200).Select(Function (x) String.Format("{0}-{1}",x.First(), x.Last())).ToList()
2 Likes

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