Expression Error in Client

I currently have a LED display with the below expression. It is pulling a substring from 2 text fields that an operator populates to see if they match. It works very well, except when the field is cleared to type the next value it errors. My question is how do I write the expression to be 0 when there is no text in the field. It works fine in the designer but in client it errors and does not work. I am new to writing expressions so this may be a no brainer for many.

Value expression
if (substring ({Root Container.Generic Data.text},1,5) = substring ({Root Container.Serial Number.text},2,6),1,0)

Text Expression
if({Root Container.Displacement Display.value}, "Launch", "Stop")

Thank you,

The expression language has a try function that you could wrap your expression in and supply a failover value.

try(someExpression, 0)

Thank you for the response. It took me a couple of tries, as I am new to python, but was able to get it working.

Thank you!

The expression language is not Python and doesn't use Python syntax. You can think of it working like Excel's formulas (but without the opening '=' operator). The expression is one continuous expression. It doesn't do multiple sequential statements. It is, however, very tolerant of line breaks and indentation so it is easy to make indented readable expressions with comments using the // comment syntax. The expression in your original post could be formatted as shown below. Which is easier to debug?

if(
  substring({Root Container.Generic Data.text}, 1, 5) 
    = substring({Root Container.Serial Number.text}, 2, 6),
  1,    // They match.
  0     // They're different.
)

An expression just returns a value (or set of values).

Since your expression above is checking for equality and returns a 1 or 0 you could consider reducing it to

substring({Root Container.Generic Data.text}, 1, 5) 
    = substring({Root Container.Serial Number.text}, 2, 6)

which would return a boolean true / false.

https://docs.inductiveautomation.com/display/DOC81/Expression+Language+and+Syntax?searchId=P1DJ2UVTQ