How to check if my string contains value or not?

Hello All,

I am extracting a string from UI Element using Get Text and storing that value in variable var1.

I will proceed only if value get extracted means var1 contains value.
How to check if var1 contains value or not?

1 Like

var1.contain(“your value”)

here value is not constant, it can be anything like 1-786786786 , 1-87678987, 1-897878978 like this

array(i) → this contain dynamic values.
var1.contain(array(1)).toString

@Karan28 From this string which value wants to check and this format will be same or different

what is (i) here?

format will be like this only , but we cant specify so as conculsion we need to check if variable contains value or not

i is a an int value… 0,1,2,3,4,5 etc…
when you split your string values by comma separation 1-7323242324, 1-3453453,1-23453432
array(0) = 1-7323242324
array(1) = 1-3453453
array(2) = 1-23453432
Then your final checking string would be as follows:
var1.contain(array(i)).toString

Hi @Karan28,
Just try this condition:
image
“test” in my case i just variable name.

@Karan28 Can you please confirm now you needs to check contains or you needs to check number should be in the proper format or not.

first I needs if it contains the value

String.IsNullOrEmpty(Var1) can check if the string is empty or contains any value.

@Karan28 You can check in if condition like this

if (IsNothing(urvariable))

{

}

thankyou it worked , but can I also check if it contains the valuee like this - 3-133439401
3-133439413
3-133439424
3-133439435
3-133439446
3-133439457

This condition checks overall if the mentioned variable has any value. It’s not checking the specific value.

do you suggest what I do if we needs to check this type of value?

Then you can use condition like this:
image
If you want to use both conditions then you can write like this:

test is not nothing and test.contains("32424")
1 Like

If you have this (Say Var2 contains any one of these values ->3-133439413,3-133439424 etc) values in variable, then compare as suggested in previous replies.
First check

if (IsNothing(urvariable)) OR String.IsNullOrEmpty(Var1)
else
var1.contain(Var2)

1 Like

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