0

I am looking for information on how to read

<td class="NumberCell" width="60">2</td>

value 2 from this tag of html?

2 is a variable value - it can change.

How to modify this to get value present in tag?

File 1 has : 2 File 2 has : 6 File 3 has : 10

I want to extract all 3 values

2 Answers2

2

As @John Told in comments try HTMLAgilityPack

using HtmlAgilityPack;
HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml("<td class=\"NumberCell\" width=\"60\">2</td>");

            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("td"))
            {
                Console.WriteLine("text=" + node.InnerText);
            }
Bhushan Muttha
  • 420
  • 2
  • 11
  • regex.Match("2"); 2 is a variable value - it can change. How to modify this to get value present in tag? File 1 has : 2 File 2 has : 6 File 3 has : 10 I want to extract all 3 values – Vinay Kumar Feb 05 '20 at 09:07
0

You could use the expression >(.*?)< to do this. This pretty simple expression will give you one matching group.

Here is a simplified implementation in C#:

var regex = new Regex(">(.*?)<");
var match = regex.Match("<td class=\"NumberCell\" width=\"60\">2</td>");
Console.WriteLine(match.Groups[1].Value);
Alexander Schmidt
  • 5,631
  • 4
  • 39
  • 79
  • regex.Match("2"); 2 is a variable value - it can change. How to modify this to get value present in tag? File 1 has : 2 File 2 has : 6 File 3 has : 10 I want to extract all 3 values. – Vinay Kumar Feb 05 '20 at 08:59
  • @VinayKumar Question back: Do you have any knowledge in Regex? The desired behavior described by you is exactly what regex is doing for you. – Alexander Schmidt Feb 05 '20 at 11:48