How to return a percentage of how much of a String A shows up in String B

Hello I have an automation where I have to choose a option based on the “best” answer so I want to compare two texts and see how similar they are for example Var A: {R/T Coupe 2D} Var B {R/T Plus Coupe 2D} and they are compared to Var C: {2018 Dodge Challenger R/T RWD}

So Var A would be best

contains doesn’t work because it only tells me if the string appears.

Hi @Carlton_Morrissey

You can split the string on space and check contains of each separate word and then which ever gives the maximum matches is your string

cheers

how would I test each array if every string has a didn’t number of words it changes all the time

Hi @Carlton_Morrissey

This is how you will get number of matches. The string can vary and contain any number…Just replace them with variables

system.Text.RegularExpressions.Regex.Matches(“2018 Dodge Challenger R/T RWD”,String.Join(“|”,“R/T Challenger Coupe 2D”.Split(" "c))).Count

This will give you the match count

If matches are equal then you can choose the string with less words as per your requirement

cheers

This sounds like exactely what I need the only thing is I am getting an error when I try it. Heres the error any ideas?

Source: Set Variable Value

Message: Expression Activity type ‘VisualBasicValue`1’ requires compilation in order to run.

Hi @Carlton_Morrissey

Just replace the inverted commas again in your code. Its the dot.net compatibility with different inverted commas

cheers

This Worked great thank you

1 Like

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