Kerberos Kerberos - 1 year ago 153
C# Question

How to apply substring-after and substring-before functions

My html structure as below

<td class="opps">1:2</td>

I am trying split value of td with XPath as below

.//*[contains(@class, 'opps')]/text()[normalize-space(substring-after(., ':'))]
.//*[contains(@class, 'opps')]/text()[normalize-space(substring-before(., ':'))]

But value returns 1:2

How can i extract 1 and 2 separately?

I am also using HtmlNodeNavigator and HtmlAgilityPack.

What is the wrong?

Thank you in advance.

Answer Source

i found a solution after more search.

if use HtmlNodeNavigator or XPathNavigator, solution is possible as below

string _result1 = <HtmlNodeNavigator>.Evaluate("substring-after(.//*[contains(@class, 'opps')]/text(), ':')") as string; 
string _result2 = <XPathNavigator>.Evaluate("substring-before(.//*[contains(@class, 'opps')]/text(), ':')") as string;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download