How to remove image source from html content?

Hi,

Here is my code, I wanna remove image source from HTML content. 

Please provide some solution to achieve this task.

 <div class="col-md-12">

    @Html.Raw(item.Content)
 </div>
Last updated:3/12/2018 11:23:11 PM

1 Answers

Harsh kumar srivastava
Harsh kumar srivastava

Hi Ethan,

Follow these steps to achieve your task.

Step 1. Write below a line of code at top of the page.

@{
    string regexImgSrc = @'<img[^>]*?src\s*=\s*[''']?([^''' >]+?)[ '''][^>]*?>'; }

Step 2. And modify your code as follows.

<div class='col-md-12'>
    @Html.Raw(System.Text.RegularExpressions.Regex.Replace(item.Content, regexImgSrc, ''))
</div>

Hope it's helpful !!!


Answer