0

I have an HTML file, for example, the content of the following code

<td><input readonly="readonly" class="input_field" onclick="highlight(this);" type="text" style="width: 605px;" value="c:\my-folder\images\123456.jpg"></td>
<td><input readonly="readonly" class="input_field" onclick="highlight(this);" type="text" style="width: 605px;" value="[URL=c:\my-folder\viewer.php?file=123456.jpg][IMG]c:\my-folder\images\123456_thumb.jpg[/IMG][/URL]"></td>
<td><input readonly="readonly" class="input_field" onclick="highlight(this);" type="text" style="width: 605px;" value="[URL=c:\my-folder\][IMG]c:\my-folder\images\123456.jpg[/IMG][/URL]"></td>


<td><input readonly="readonly" class="input_field" onclick="highlight(this);" type="text" style="width: 605px;" value="c:\my-folder\images\654321.jpg"></td>
<td><input readonly="readonly" class="input_field" onclick="highlight(this);" type="text" style="width: 605px;" value="[URL=c:\my-folder\viewer.php?file=654321.jpg][IMG]c:\my-folder\images\654321_thumb.jpg[/IMG][/URL]"></td>
<td><input readonly="readonly" class="input_field" onclick="highlight(this);" type="text" style="width: 605px;" value="[URL=c:\my-folder\][IMG]c:\my-folder\images\654321.jpg[/IMG][/URL]"></td>


How can I have the following output in a text box in C#?

[URL=c:\my-folder\viewer.php?file=123456.jpg][IMG]c:\my-folder\images\123456_thumb.jpg[/IMG][/URL]
[URL=c:\my-folder\viewer.php?file=654321.jpg][IMG]c:\my-folder\images\654321_thumb.jpg[/IMG][/URL]

    string data ="<p>this is new document<img alt='' height='150' src='https://mysit..jpg' width='200'/>This is new document</p>
";
            var newdt = FetchImgsFromSource(data);
        public static List<string> FetchImgsFromSource(string htmlSource)
        {
            List<string> listOfImgdata = new List<string>();
            string regexImgSrc = @"<img[^>]*?src\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>";
            var matchesImgSrc = Regex.Matches(htmlSource, regexImgSrc, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            foreach (Match m in matchesImgSrc)
            {
                string href = m.Groups[1].Value;
                
                listOfImgdata.Add(href);
            }
            return listOfImgdata;
        }

In the code above, how to put the href variable content in a text box!? r return the href value instead of the number

2
  • 1
    What have you tried? Please see minimal reproducible example and How to Ask. SO is a site to help solving specific problems, not coding at your place. Please show us attempts you made and why you didn't succeed. That said, HtmlAgilityPack is your best friend when you have to parse HTML in .Net Commented Mar 6, 2024 at 14:15
  • In the code above, how to put the href variable content in a text box!? r return the href value instead of the number Commented Mar 8, 2024 at 13:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.