Pass two lists through one validation

I have two lists that i need to iterate through and validate.

ListOne (of string) contains:
Test1, Test2-, tes’t, te-st

ListTwo (of string) contains:
test3, tes-t4, te’st5

I have validation which removes special characters. When i pass ListOne through this it adds each item to a new collection (ListOneFinal). I’d like to do the same for ListTwo, but i don’t want to repeat my code.

My plan was to create a list variable of type string with {“ListOne”, “ListTwo”} then, using a switch, invoke a workflow to loop through the list using the regular expression to remove special characters & add to a new (final) collection, ListOneFinal list (of String). I cannot seem to do that as it loops the string ‘ListOne’ and productes L, i, s, t, O, n, e. I cannot seem to create a List (of string) to loop {ListOne, ListTwo} as i receive an error that it cant assign from generic list [system string] to generic list [system string]

There was a suggestion to add both Lists to a List of Lists however, in my Watch window i can see Type List<List> Value= List<List> (2){null, null}

Is there another way I should approach this please?

1 Like


You can concatenate two lists as below and can perform your tasks…Just tried


Regex.Split(str,"\W").ToList.concat(Regex.Split(str,"\W").ToList).Select(function(x) Regex.Replace(x,"\W","")).ToList

Equivalent to ListOne.Concat(ListTwo).Select(function(x) Regex.Replace(x,"\W","")).ToList

Please try and let us know if you face issues


Sorry i’m a bit confused as i need to feed in two separate lists & recieve two separate lists as output as the results go in to two separate collections. I can’t join or concatinate them. I can see the confusion though as the test data I provided is very simalar in the separate lists

ListOne (of string) contains:
Amy1, Beth2-, C’hris, Da-vid

The final result going in to ListOneFinal should be: Amy, Beth, Chris, Da, vid

ListTwo (of string) contains:
test3, tes-t4, te’st5

The final result of ListTwoFinal should be: test, tes, t, te,st


If you need two separate lists then need two separate then please do the task two times

ListOne.Select(function(x) Regex.Replace(x,"[^A-Za-z]","")).ToList

Same for list two again

This will retrain only A-Z and a-z and replace everything else


1 Like

Why not just combine the two lists into one and then run it through the validation?

Thank you, that makes sense. The only thing is that there should be a new list item created when the special character is removed. Is it possible to include this in the assign?

The outputs need to be placed in separate lists according to the original source


Give a new list of type List and the value would be assigned to the new list

Newlist1 = ListOne.Select(function(x) Regex.Replace(x,"[^A-Za-z]","")).ToList

If it throws error then initialize the list NewList1 = New List(Of String)



How about the following sample? Is this what you expect?

ListList = ListList.Select(Function(x) x.SelectMany(Function(s) System.Text.RegularExpressions.Regex.Split(s,"[_\W]+")).ToList).ToList (2.5 KB)


1 Like

When i use ListOne.Select(function(x) Regex.Replace(x,“[^A-Za-z]”,“”)).ToList is modifies my original list from Amy, Beth, Chris, Da, vid TO: Amy, Beth, Chris, David rather than Amy, Beth, Chris, Da, vid

For ListTwo.Select(function(x) Regex.Replace(x,“[^A-Za-z]”,“”)).ToList
It modifies it from test3, tes-t4, te’st5 to test, test, test rather than test, tes, t, te, st

Ideally where a special charaver is found it’d create a new list item in each list

If i modify your Regex to ListOne.Select(function(x) Regex.Replace(x,“[^A-Za-z]”," ") to create a space in place of the special character, I can loop through each list item & split where there is a space however i’d again need to pass both lists through a loop to do this twice. Is there a better way to approach?


Thank you Peter though, where a special charaver is found witin the list, it needs to split & create a new list item in each list. Is there a way that this can be achieved?

this requirement differs from original requirement desciption. So clear complete requirements at the begin (best with output sample) helps to speed up the solution findings

So just share input / output samples. Thanks

Above could be understood as:

But we do feel something different is targeted

OK, I misunderstood the above statement then.


Okay now I got your requirement completely I guess try this

Newlist1 = Regex.Split(String.Join(",",ListOne),"[^A-Za-z]").Where(function(x) Not String.IsNullOrEmpty(x)).tolist

Regex.Split(String.Join(",",{"Tst1","Test-te"}),"[^A-Za-z]").Where(function(x) Not String.IsNullOrEmpty(x)).tolist

Output as required:

So now this will create a new list with splitting the individual words again on the special characters

As per your input (4 strings as input and 5 as output as one string has special characters in it so it would be split



That is excellent! Thank you very much - exactly what the process needed.

Thank you all for your time & continued support.

1 Like

@ppr Can you tell me what variable type arrAllCleansed was in your example above please?
I have tried List , String , List<List> but to no avail. I’m just looking to improve my learning, thank you.

array of String List - List(Of String)()

1 Like

Thats great, thank you very much

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