Find inconsistense in collection of string

Hello there

I am looking for some guidance on a small piece of “code” for my RPA project.
I havent worked with collections of strings before and therefor am looking for some guidance in developing this small process code.

I need to figure out, how to create and add a string to a collection - and in the end, i need to examine the collections for any inconsistens. I am expectiong all strings to be equal and contain only numbers.

Could anyone help me out with some guidance? :slight_smile:
Cheers

J

@JDK
Doing IT with a String list
Define a variable of Datatype(of String)
And init IT within assign Activity or Default value with: new Datatype(of String)

Adding a String can be done with the add to collection activity

Value Check can be done with:

  • Regex using IT within a for each loop
  • Or a linq statement
1 Like
  • Where is the values you want to add are coming from?
  • Is better to add the validation right before adding to the list, instead of doing in the end
  • If all is going to be numbers, why not use collection of numbers instead?
1 Like

Values comes from get text activites, which are placed in a loop for X times.
By adding a string - or number - to a collection i Can compare when loop is over :slight_smile:

Cheers

Thank you very much. Ill try and make it tomorrow :slight_smile:

I am not used to working with regEx - Can you help me with the code?
I Will always have either 2 or more In the collection - max 50 total.

Mission is to locate inconsistensis within the collection. There should max be 1 inconsistensi - but might be more; i am now sure…

Hi @JDK,

  1. Create a list with string as the datatype for individual items.
  2. Add item to the list
  3. Create a Loop to Compare the strings
  4. Compare the strings using Strings.StrComp(s1,s2) function - for Basic Comparision or RegEx - for advanced comparison
lsStrings = new List<string>();
lsStrings.Add("Hi");
lsStrings.Add("Hi");
boolCompare = Strings.StrComp(lsStrings(0),lsStrings(1))
1 Like

@JDK, I am happy to help you out… Kindly share the input text and logic based on which you want to do comparisons… I will share the regex pattern to you.

Hi,

Values are random but always 8 Numbers Long - eg. 88226644

I want to compare all items in collection with eachother to find inconsistensies.

Eg.
3 items in collection
1: 22332233
2: 22332233
3: 33223322

I basicly just need to know if inconsistensy exists or not. I dont need the value if that makes a difference :slight_smile:

@JDK, Did you like to check, Whether the numbers or strings are 8 digit long or not

No, check already ok. :slight_smile:

Hi

we can do this with the help of ADD TO COLLECTIONS activity where the input string to be added must be mentioned in item property and the list or collections variable in collections property
–and change the type argument as STRING

and for this

for this use a assign activity like this
str_input = listvariable(0).ToString
–then use a FOR EACH activity and pass the above variable listvariable as input and change the type argument as string
–inside the loop use a IF condition like this
Isnumeric(item.tostring) and str_input.Equals(item.tostring)
only if both these condition passes it will go to THEN part of IF condition or goes to ELSE part

Cheers @JDK

Did u have time to create regEx?

I am not able to clearly understand what you are trying to do. Can you clearly produce the scenario like, Input, Conditions Needs to be applied and Output. So that i can help you out.

Are you trying to find the whether a duplicate is present in the collection or not ?

Else

Are you trying to ensure all the numbers in the collection are same or not?

Trying to make sure that all Numbers are same

I will share the code in a bit… @JDK

Hi @JDK,

I have created a workflow file which will help you to check the consistency of the collection of strings.

Input: Array of Strings (DatayType - Array[strings])
Ouput: Consistent or not (DataType - Bool)

ConsistencyCheck.xaml (5.7 KB)

Process:

  1. Select the count of unique strings in the collection of strings (Array of Strings)
  2. If count is equal to 1 then the String Collection is Consistent otherwise not.

Pesudo Code:

cntUniqueStrings = arrStrings.Distinct().Count()
IF cntUniqueStrings = 1
  Consistent
Else
  Not Consistent
1 Like

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