How to create list of strings (5 characters per string?)

Hello,

I have created a list of strings like this one:
“123456
789
123456”

I would like to convert it into:
“12345
67891
23456”

So that each sentence has 5 characters.

Thanks!

Hi,

I dont know how to do it in a simply way. I guess that I would make a loop in fact to get each string of the list and then apply some logic, like substring or something like that…

If I have time I will try to make a test.xaml for you

Regards,
Pablo

take the whole string split it by delimiters(newline). make a single continues string of the numbers. iterate the string with a counter of 5 and then enter a new line. you will get the desired result.

First you would need to combine the list of strings into one:
StringList = String.Join(" ",List)

Then you would need to split that string again based on a substring of 5 characters:

List = Enumerable.Range(0,StringList.Length\5).[Select](Function(i) orig.Substring(i*5,5)).ToList()

1 Like

Nice @TimK

I was on the same track :slight_smile:
Just if you want to see how the result is:

  1. System.Text.RegularExpressions.Regex.Replace(address,"[\n]","")

  2. Enumerable.Range(0, Cint(lines.Length/5)).[Select](Function (i) lines.Substring(i*5,5)).ToList

2 Likes

See if this helps

printNumbers.xaml (27.1 KB)

The address data type would not accept the string,
“123456
789
123456”. for my ui path. Can you clarify that?

1 Like

it will, just click on Ok and you should be good.

yeah, should have just tried :slight_smile: thanks :+1:

1 Like

Thanks.

“address” in my case should be a list of strings, not a unique string.

Would that work?

Small Tweak.

lines = String.Join("",address)

1 Like

Thanks a bunch.

Best regards. Have a nice weekend.

1 Like

One more question. What if the list of strings is like this one:

“123456
123”?

I should be like
“12345
6123”
I think your solution does not work in this case. Am I right?

No, that logic will not give you this result.
it depends on the length being a multiple of 5.

For all cases if you want to split. Example- 5,4 or, 5,1 or, 5 or 5,5,1 or 5,5,5

Enumerable.Range(0, Cint((Math.Round(lines.Length/5.0)*5)/5)).[Select](Function (i) lines.Substring(i*5,Math.Min(lines.Length - (i*5),5))).ToList

I make the count a multiple and then i chunk it to x5 and then renaming :slight_smile:

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