Separating the code tag from the text and html in C#

24 Views Asked by At

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

0

There are 0 best solutions below