If Statement condition c# is not working


I am a begginer user, and just wanted to make a verification in an assing activity, basically to check if a string contains “< $” then if true replace “< $” by “” else replace “$” “”.

I made this :
if(strAmazonStorageCost.Contains(“< $”), strAmazonStorageCost.Replace(“< $”,“”), strAmazonStorageCost.Replace(“$”,“”)

I think my syntax is right, but getting the error: Error

ERROR Validation Error Invalid expression term ‘if’
; expected
) expected
Invalid expression term ‘,’
} expected

Even if I try anything simple like: if(n1>n2, “a”,“b”) still getting same error, not sure if is a library problem…

Please help!

Thanks in advance.

You’re using vb.net syntax. C# syntax is different:

This is syntax for VB language.
What is your project language - VB or C#?
You can check it at the bottom of uipath studio window

*vb.net syntax Paul

C# is also a .net language so anything in C# is also a .net syntax.

Hi @javierdavidh put the condition like this:

No. They have very different syntax. We are talking about C# vs vb.net

Hi @Konrad_Mierzwa , my project is in C#,

However I have also tryied this :

if (strAmazonStorageCost.Contains(“< $”))
strAmazonStorageCost.Replace(“< $”,“”);

Thas is suposed to be C # syntax , but got an error too:

Error ERROR Validation Error Invalid expression term ‘if’
; expected

I dont know where else put the ; ???


Hi all,

I have solved the issue by adding “if sequence” from UIpath:

However, I’m not sure this is the most efficient way, from my point of view a single c # expression runs faster than the uipath sequence… am I wrong?

I would prefer to have the c# expression, any ideas?

Thanks !

I am well aware Paul, I am fluent in VB.Net and C# which is why I am trying to help avoid confusion.
They are both .Net languages so both can be considered .Net syntax. You cannot shorten Vb.net to .net as it has a very different meaning.

1 Like

Have you tried this suggestion?

You were linked the C# syntax above. It is here.

The If statement you wrote in a later post is for a block of code and not a single line expression. Use the ? syntax demonstrated in the link.

strAmazonStorageCost.Contains(“< $”) ? strAmazonStorageCost.Replace(“< $”,“”) : strAmazonStorageCost.Replace(“$”,“”)

It works in one single line !

Thank you all !!!

1 Like

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