I'm developing software that grabs data from an html table. So this line:
team.SelectSingleNode(".//td[@class='number total won total_won']")?.InnerText.Trim();
returns: ""
(I'm using html agility pack for DOM manipulation.)
And the complete line is this:
Convert.ToInt32(
team.SelectSingleNode(
".//td[@class='number total won total_won']")
?.InnerText.Trim());
This returns an exception (incorrect format exception).
Any idea to solve this?
var str = team.SelectSingleNode(".//td[@class='number total won total_won']")?.InnerText.Trim();
var number = str.IsNullOrWhiteSpace ? 0 : Convert.ToInt32(str);
is one way to go, if you want zero value for null, empty or whitespace only string representation.