String iteration programming

62 Views Asked by At

I'd like to write a function able to generate an array of string with iteration in Go programming language.

Enter a unique name for the signal path in the field titled Description. Since the field features an iterator, multiple, consecutively counted signal paths can be set-up by using curly brackets, for example "Source {1-16:2} {Left, Right} >"

The result is an array of string:

Source 01 Left >
Source 01 Right >
Source 02 Left >
Source 02 Right >
...
Source 16 Left >
Source 16 Right >

I could have an undefined curly brackets iterator in the string.

  • The first curly brackets {1-16:2} indicate 1-16 : increment value from 1 to 16 :2 is the padding that means two digits

  • The second curly brackets [Left, Right} indicate a defined list of value.

1

There are 1 best solutions below

0
On

I don't have the code yet.

Today I have an UI interface where I have some optional fields to fill.

  • signal path : "Source" as the unique identifier (as string) (Mandatory)
  • counter : "16" increment value from 1 till 16 (as integer) (optional)

    Source 1 Source 2 Source 3 ... Source 16

If I would like to create a signal path like this:

Source 01 Left >
Source 01 Right >

I need to do it manually. If I have 1000 signal path to create it will take hours with errors and if the counter > 0 then increment value will be added at the end of the signal path and no padding.

Now I am looking some help if any libraries could analyze my string iteration "Source {1-16:2} {Left, Right}" and generate the string as expected.

Best regards, Youssef