How to use String in "IF" Condition


I have a case here where in I get conditions in Excel sheet.

Condition will be something like

  1. item.Subject.StartsWith(“IB.01”) and item.Subject.Contains(“INC”)=false

2.item.Subject.Contains(“INC0”) or item.Subject.Contains(“Melding”)) and (item.To.ToString.Contains(“ACD”) or item.CC.ToString.Contains(“ACD”))

  1. item.Subject.Contains(“OG.06”) and (item.To.ToString.Contains(“ACD”) or item.CC.ToString.Contains(“ACD”))

I need to read this and paste/evaluate it in IF Condition

But UiPath needs Boolean as value and not String.

Convert.ToBoolen function fails.



(I’m assuming you are using a ForEach row activity, so I will use row as the row that is looped through and .item as the item within the row). You also need .ToString next to each item in this case.

.Contains and .StartsWith already returns a boolean. If you want it to be false then add “NOT” infront. Also, the column name goes in parentheses.

For example,
not (row.item(“Subject”).ToString.StartsWith(“IB.01”) and row.item(“Subject”).ToString.Contains(“INC”))

Notice I put “not” infront cause you wanted false or you can put it for only one like:
row.item(“Subject”).ToString.StartsWith(“IB.01”) and not row.item(“Subject”).ToString.Contains(“INC”)

Also, following the order of operations, “or” is similar to “+” and “and” is similar to “x”. So, make sure to use parentheses to group the "or"s together.

For example,
(row.item(“Subject”).ToString.Contains(“INC0”) or row.item(“Subject”).ToString.Contains(“Melding”)) and (row.item(“To”).ToString.Contains(“ACD”) or row.item(“CC”).ToString.Contains(“ACD”))

I believe one of your problems was the “=false” which can cause an error, but since .Contains is a boolean you don’t need that part.

Hopefully this has answered it for you!



Thanks For Quick Response Clayton,

But lets assume I have stringVariable named “Condition”

and in that variable i can have any conditions like one mentioned above.

So, not(Condition) will not work in If Activity.

I need to somehow evaluate variable “Condition” to fetch its result.



Hello @AjinkyaCK,

I’m not completely sure what you mean, but if you store the condition to a string, I would suggest storing the boolean result.

For example,
Assign condition = (row.item(“Subject”).ToString.StartsWith(“IB.01”) and row.item(“Subject”).ToString.Contains(“INC”)).ToString

condition, assigned above, will equal either “True” or “False” as a string, then in the If condition you can check if it’s one of them, like
If condition = “False”

EDIT: also,
If the condition variable is of a Boolean type, then you don’t need the .ToString and the If condition would look like: If condition or If not condition


Hello Clayton,

My Requirement is like this:

  1. I have an Excel Sheet which has rules defined (3 examples).
  2. Now there is one location in workflow where I want to validate if the rules are correct or not.
  3. These Rules are dynamic in nature i.e. I have 30+ Rules.
  4. So I read the rules keep it in array of Strings and one by one I need to put it in IF activity to see if its true or False.
  5. Please note that I cant compare this String with any other String simply because it itself has both the operands.

I just need a way or function who can evaluate this string to fetch me output in form of Boolean.


So I understand it as you needing the equivalent of Eval() or Evaluate() in UiPath.
I’m not sure that’s available in UiPath, but if it is I would like to know! A few of us here have asked the same questions.

I think you will need to go about your condition in another manner.
Let’s say you have values in Excel that form a condition…
You can then place a formula to calculate that condition and you can read the cell’s value to a variable in UiPath. You then can use that string in the condition such as… condition=“False” or cbool(condition)=False , where condition is a variable containing the word True or False

I bet there are other possible solutions to this as well.

Unfortunately, I do not know of an equivalence of the Eval() function. I thought maybe Microsoft.VisualBasic. might have something but don’t see it.




You could be trying to store your conditions as Regex patterns and use a for each to iterate through the patterns to check if your string is a match with one of them

What would make this tedious for your case is that your conditions concern several properties of your email (Subject,To,CC). You could priorly concatenate those properties into one string but this might have some drawbacks

Good luck :slight_smile:


Reading this may help -

It may be required to write a separate xaml where you pass your condition in string format and get its result back in a Boolean format which can be used in the IF condition.