# I need to check if the second variable contains 70% of the first variable

Hi,
I have two variables. I need to check if the second variable contains 70% of the first variable. The variables will differ in each transaction. I would appreciate your help.
Note: Variables are not exactly compatible. There may be letter differences in the first or second variable.

Example variables:
First Variables : Uipath Community Preview Release
Second Variables : Uipeth Com Previe Rela

Hi @ridvanucok ,

I would suggest you to use String Similarity Algorithms for your case.

Just Check the Similarity Score between the Strings using the Component below. You could use it if satisfied.

Else we would need more details as to How the Strings are Matching to 70% in your case.

1 Like

Hi

you can check this,

thank you
debakanta

1 Like

There is a structure created with the Levenshtein algorithm. I am looking for an alternative solution for the operations that are insufficient with this algorithm.

Hi

you can implement below vb code or modify as per your requirement

Dim count As Integer = If(str1.Length > str2.Length, str1.Length, str2.Length)
Dim hits As Integer = 0
Dim i, j As Integer : i = 0 : j = 0
For i = 0 To str1.Length - 1
If str1.Chars(i) = " " Then i += 1 : j = str2.IndexOf(" "c, j) + 1 : hits += 1
While j < str2.Length AndAlso str2.Chars(j) <> " "c
If str1.Chars(i) = str2.Chars(j) Then
hits += 1
j += 1
Exit While
Else
j += 1
End If
End While
If Not (j < str2.Length AndAlso str2.Chars(j) <> " "c) Then
j -= 1
End If
Next
perc= (Math.Round((hits / count), 5)*100).ToString

thank you
debakanta

1 Like

Hi @Debakanta_Mahanta ,
I will try. thank you.

Hi,
Do you have any alternative solutions?

Hello @ridvanucok,

You could try the following logic:

• use the replace() function on each string to replace the " "(white spaces) with â€śâ€ť(nothing). â€śthis is a random stringâ€ť will become â€śthisisarandomstringâ€ť.
• use the split() function on each string to split these 2 strings into arrays of strings. Each array item will contain a letter in your string. The array for the string above will become {t,h,i,s,i,sâ€¦etc.}
• use a For Each loop to iterate through the items in the second array. In this loop add a new For Each loop to iterate through the items in the first array.
• in the second loop add a counter variable (like counter = counter + 1) and add an If statement: if array2Character = array1Character (meaning if the caracters from both strings are the same) then counter increases with 1. If not, do nothing (and then the loop will go to the next array item/letter).
This way you would get how many matches are between data in string 1 and the data in string 2.
I would use the counter value to divide it by the legth of the string (by using the Length() function) and get the match ratio/percentage. So if my counter = 7 and the length of the string is 10 then 7/10*100 = 70% match.

Hope this helps

1 Like

@AlexGabriel97 ,
Thank you very much for your comment. I will try this too. If you have different alternative solution suggestions, can you share them again? The more solution proposals there are, the more successful the transaction count will be.