Q:

Substring when a string contains, Linq syntax

in Linq i have somthing like 
nodes.Select(td => td.InnerText.
                Replace("&amp;", "&").
                Substring(0, td.InnerText.IndexOf("+"))).
                ToArray();

some times td.InnerText contians a + sign and sometimes it doesn't and if it doesn't i get null reference exception.
how can i apply Substring(0, td.InnerText.IndexOf("+"))) only if td.InnerText contains "+" ?

A:

you can do this
td.InnerText.Replace("&amp;", "&").Substring(0, td.InnerText.IndexOf("+") > -1 ? td.InnerText.IndexOf("+") : 0);

