Condition needed in IF part

Hi All ,

Basic questions…
I want to apply if condition
Possible string ->Teststring1 = New(dynamic name)*
Teststring2= New
Teststring3= New(dynamic name)
Teststring4 = Old

I want a if condition such that it will accept teststring2 or teststring3
For rest all values it goes to Else part.

Hi @TD_Learner

Try this:

If Teststring.StartsWith("New") AndAlso Not Teststring.StartsWith("New(")
    Then
        // Actions for Teststring2 and Teststring3
    Else
        // Actions for other cases

Regards

@TD_Learner

Teststring.StartsWith("Teststring2") Or Teststring.StartsWith("Teststring3")

@TD_Learner

you can try this

Teststring.ToLower.trim.equals("new") Or Teststring.ToLower.EndsWith(")")

Hi @TD_Learner

Try this:

Teststrings= {"Teststring1 = New(dynamic name)*", "Teststring2= New", "Teststring3= New(dynamic name)", "Teststring4 = Old"}
For Each Teststring in Teststrings
    If
       (Teststring.StartsWith("Teststring2")) OrElse (Teststring.StartsWith("Teststring3"))
    Then
          Write Line-> "Teststring2 or Teststring3 detected."
    Else
          Write Line-> "Other cases detected."
    End If
End For Each

Teststrings is of DataType Array(System.String)

Output:
image

Hope it helps!!

Name in the string are dynamic and we can’t keep track … consider it is random name

So robot allow only “New” or “New(dynamic name)”

Hello @TD_Learner

Assuming your test strings are like the below:
Teststring1 = New(AAA)*
Teststring2 = New
Teststring3 = New(BBB)
Teststring4 = Old

Insert the following into your IF statement condition:
System.Text.RegularExpressions.Regex.IsMatch(INSERTxTESTxSTRING, “New$|New\(.+\)$”)
*Just replace the capital letters with your string variable.

See results in below image:
image

Hopefully this helps :blush:

Cheers

Steve

@TD_Learner

Is this what you are looking?

TestString1.Equals(TestString2) Or TestString1.Equals(TestString3)

This gors to then else any other string in teststirng1 will go to else part

Cheers

Hi @TD_Learner

Can you specify some more random inputs too.

Regards