Hello,
I have a List of String. For example:“A111,A112,A113,A116,A117,A119”
How to get a new List like as “A111-A113,A116-A117,A119”?
Thank you.
Hello,
I have a List of String. For example:“A111,A112,A113,A116,A117,A119”
How to get a new List like as “A111-A113,A116-A117,A119”?
Thank you.
Welcome to the UiPath Forum
You can use a for loop and check if the current item is the successor of the previous element, and is not tout can create the range from starting item to current item in loop
@Bosch
we con do it with the help of grouping the segments using a dictionary
Variables:
Init:
Grouping
Creating result
Debug/Inspections
Find starter help here:
GetRangeSegments_byStringDigitSequence.xaml (10.4 KB)
Thank you!!
This worked!
I don’t know how to express my gratitude…
Thank you!!
I will try this!
Excuse me, if I add another condition…
…=>More than three consecutive
For example:“A111,A112,A113,A116,A117,A119”
How to get a new List like as “A111-A113,A116,A117,A119”?
Thank you!!
Give a try on edited LINQ
ListResult =
(From kvp In dictSegments
Let doMerge = (kvp.Value.Count >= 3)
Let sgm = If(doMerge , {kvp.Value.First() & "-" & kvp.Value.Last()}.toList,kvp.Value )
Select s=sgm).SelectMany(Function (x) x).toList
sample did show 3 or more, otherwise change >=3
to >3
Thank you!!
This worked!
I will try to learn RegEX~
it is LINQ code
thx for your link
Have benefited a lot~
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.