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

  • 6
    It's typically less error-prone to read HTML with a dedicated HTML parsing library, such as HtmlAgilityPack. – DiplomacyNotWar Feb 05 '20 at 07:01
  • Please embed the code instead of providing an image. – RyanNerd Feb 05 '20 at 07:02
  • 1
    If you want to parse a whole HTML-File, please just read this answer (it's totaly worth reading, maybe the best answer on this site ever): https://stackoverflow.com/a/1732454/3246824 – Dennis Rieke Feb 05 '20 at 07:09

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
  • 400
  • 1
  • 10
  • 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,296
  • 4
  • 36
  • 72
  • 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