I have multiple patterns that I want to expand. Expansion should expand number and letter ranges between curly braces. Numbers need to support padding. I want to have it expand into a List(Of String)
for ease of iteration. Patterns may include multiple sets of curly braces and they can be in any position.
Here are some example patterns and what they should expand to:
Example 1
randomtext-aaa-bbb-ccc-{08-10}_abc
randomtext-aaa-bbb-ccc-08_abc
randomtext-aaa-bbb-ccc-09_abc
randomtext-aaa-bbb-ccc-10_abc
Example 2
other_random*text={1-2}
other_random*text=1
other_random*text=2
Example 3
{01-02}_more_random-things
01_more_random-things
02_more_random-things
Example 4
yet-another#random_example-{a-d}
yet-another#random_example-a
yet-another#random_example-b
yet-another#random_example-c
yet-another#random_example-d
I tried using for loops and sub strings, but it very quickly got confusing and illegible. So how would I go about this without having confusing, illegible code?
6
So how would I go about this without having confusing, illegible code?
You can either solve the generating problem with recursion or with dynamic data structures that mimic the effect of recursion.
Both are confusing if you don’t now the concept yet, but recursion will stop being illegible once you understand it, while the custom data structures will likely remain illegible for good. The obvious recommendation is for you to learn recursion – it is one of the few programming concepts that will almost certainly make you a better programmer, and that will stay with you throughout your career, log after you’ve solved this one problem.
1