0

I am using SQL Server 2012 and my data and image is inserted from a richtextbox from asp.net and I need help to display only text, not image, from the specific field from the table.

Here is an example:-

<p>The Brando is an exquisite luxury resort on French Polynesia&rsquo;s breathtakingly beautiful private atoll of Tetiaroa,
   <img style="width: 100%;" src="../images/InfrastructureImage/The Brando, French Polynesia 2.jpgc05350ab-ba5d-465f-91da-4b9edb8fce47.jpg" 
  alt="The Brando, French Polynesia 2.jpg" />
</p>

into this example I want only text not image which is on the <img> tag I want to remove the complete image tag. I need help fetching only the text.

Please help me with this

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user3364191
  • 11
  • 1
  • 5
  • You can use `html agility pack` [question on SO](http://stackoverflow.com/questions/846994/how-to-use-html-agility-pack) – शेखर Jan 12 '16 at 06:03
  • In sql server you can use user define function [similar question on SO](http://stackoverflow.com/questions/457701/best-way-to-strip-html-tags-from-a-string-in-sql-server) – शेखर Jan 12 '16 at 06:15

2 Answers2

0

In your dataLayer

Text = Regex.Replace(reader["Htmltext"] as string, "<img.*?>", String.Empty);
0

Split and get. Not a clean process but its work.

string YourReceiveValue="<p>The Brando is an exquisite luxury resort on French Polynesia&rsquo;s breathtakingly beautiful private atoll of Tetiaroa,<img style="width: 100%;" src="../images/InfrastructureImage/The Brando, French Polynesia 2.jpgc05350ab-ba5d-465f-91da-4b9edb8fce47.jpg" alt="The Brando, French Polynesia 2.jpg" /></p>"
string[] result = YourReceiveValue.Split(new string[] { "<img" }, StringSplitOptions.None);
string RemoveImage=result[0] + "</p>"; // Get back Closing tag of p
4b0
  • 21,981
  • 30
  • 95
  • 142