0

I need to find the part of the string between the two tags :

First tag <h3><a href="/questions/
Last tag " class

I'm trying to use indexof and substring but what should I do with the substring ?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyString
{
    public partial class Form1 : Form
    {
        private string htmlCode = "";

        public Form1()
        {
            InitializeComponent();

            var myString = GetSources();

            int index = myString.IndexOf("<h3><a href=") + 11;
            string restulr = myString.Substring(index, )

            // <h3><a href="/questions/ 
            // " class
        }

        private string GetSources()
        {
            using (WebClient client = new WebClient()) // WebClient class inherits IDisposable
            {
                htmlCode = client.DownloadString("https://myStringTest.com");
            }

            return htmlCode;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
Jean Flores
  • 143
  • 1
  • 1
  • 6

1 Answers1

-1

Use RegEx to separate HTML or use the Html Agility Pack (HAP).

RFE Petr
  • 647
  • 2
  • 7
  • 19