Find if extact word is available in the String

Str_Variable1 = 27BBFA6059P1Z

Str_Variable2= BBFA60

Need to validate if the Str_Variable1 contains the exact string available in Str_Variable2

Hi @Sathish_Kumar_S

If Str_Variable1.Contains(Str_Variable2) Then
Console.WriteLine(“Match found”)
Else
Console.WriteLine(“No match”)
End If

If this answers to your query kindly close this case by marking it as Solution.

Happy Automation

One of many options:

Assign activity:
hasFound | DataType: Boolean =
strVar1.Contains("BBFA60")

for a simple contains

When

is to describe a different scenarion, then elaborate more about it

I would like to find if only all the strings avaiable in str_var2 is available in str_var1

use the method shared by me. use the activity

if activity:
In condition: Str_Variable1.Contains(Str_Variable2)

infortunately the statement “all the strings” is creating new open questions

the String “BBFA60”, a series of chars, will be used in all for the check.

Maybe you a are looking for an equals check strVar2 = strVar1 →
strVar1.Trim.Equals(strVar2.trim)

Otherwise share with us the scenario with two samples:

Positive Scenario - Sample data for the matched condition
Negative Scenario - Sample data for the unmatched condition

BTW:
such prototyping can be done yourself directly within the immediate panel:
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

Positive Scenario - Sample data for the matched condition

Str_Variable1 = 27BBFA6059P1Z

Str_Variable2= BBFA60

Negative Scenario - Sample data for the unmatched condition

Str_Variable1 = 27BBFA6059P1Z

Str_Variable2= BBFA6

both are positive scenarios, as there is no consistent rule which formulates which char is allowed after string2 in string1 or is not allowed

1 Like

For this, I believe you need to build an automation using regex, if you have a concrete pattern for String2 that can be compared to check if it is present in String1.

@Sathish_Kumar_S,

I feel something isn’t clear here about what you are trying to achieve. I understand positive scenario but negative scenario, how you are deciding BBFA6 isn’t there because I can see it and code will also be able to see it. Anything we are missing?

1 Like

All strings present in str_var2 must also be contained in str_var1. If even a single string from str_var2 is missing in str_var1, then it should be considered not a match

27BBFA6059P1Z is containing BBFA6 so it is not a negative scenario. You also mentioned here:

Here is the correct requirement :

Except the first 2 string in str_var1 then reamining 10 string should match with str_var2
Ignore the first two strings in str_var1.
After that, the remaining 10 strings in str_var1 must all be present in str_var2.
If even one of those 10 strings is missing from str_var2, then it should be considered not a match

@Sathish_Kumar_S,

It might be clearer if you explain this with an example

1 Like

Postivie :

Str_Variable1 = 27BBFA6059P1Z

Str_Variable2= BBFA6059P1

Negative :

Str_Variable1 = 27BBFA6059P1Z

Str_Variable2= BBCA6059P2

@Sathish_Kumar_S

I think you should ignore first 2 chars of str_var1 using str_var1.Substring(2,10) and check if it equals str_var2.
If equal > match; else > no match.

eg.-
str_var1.Substring(2,10) = str_var2

Positive: “BBFA6059P1” = “BBFA6059P1” > match
Negative: “BBFA6059P1” not= “BBCA6059P2” > no match

for
Str_Variable1 = 27BBFA6059P1Z
Str_Variable2= BBFA6059P1

and for
Str_Variable1 = 27BBFA6059P1Z
Str_Variable2= BBCA6059P2

we already gave you the hint:
strVar1.Contains(strVar2)

We also gave a tool for doing the prototypings:

Additionally find also some help on statements here:

when to incorporate more strict that the contains has to start the heck after the first two chars then feel free to combine it with substring or have a loo at a regex pattern e.g. like:


1 Like

You can try following approach

  1. Remove first 2 char in str_var1 - str_var1_temp = str_var1.Substring(2)
  2. Check if str_var1_temp contains in str_var2 - str_var1_temp.Contains(str_var2)return bool

=>Str_Variable1.Contains(Str_Variable2, StringComparison.OrdinalIgnoreCase) for case insensitive, gives True or false
=>Str_Variable1.Contains(Str_Variable2, StringComparison.Ordinal) for casein sensitive, gives True or false