I would suggest using a real HTML parser, for example HtmlAgilityPack. Then it is simple:
string html = "There is some nice <img alt='img1' src='img/img1.png' /> images in this <img alt='img2' src='img/img2.png' /> string. I would like to ask you <img alt='img3' src='img/img3.png' /> how Can I can I get the Lenght of the string?";
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
int length = doc.DocumentNode.InnerText.Length;
int imageCount = doc.DocumentNode.Descendants("img").Count();
This is what DocumentNode.InnerTextreturns to your sample, you missed a few spaces:
There is some nice images in this string. I would like to ask you how Can I can I get the Lenght of the string?
source
share