我有可能包含一个或多个图像标签字符串中删除图像标记...字符串处理,提取和从字符串
我已经写了一个片断从字符串 滤除图像标签,如
string test = "Hello there <img>Image1</img> How are you ?<img>Image2</img>";
int imgstartindex = test.IndexOf("<img>");
int imgendindex = test.IndexOf("</img>");
List<string> imagetags = new List<string>();
while(imgstartindex!=-1 && imgendindex!=-1)
{
string imagetag = test.Substring(imgstartindex, (imgendindex + 6)-imgstartindex);
imagetags.Add(imagetag);
test= test.Replace(imagetag, "");
imgstartindex = test.IndexOf("<img>");
imgendindex = test.IndexOf("</img>");
}
输出:
test="Hello there How are you?"
imagetags:
"<img>Image1</img>" [0]
"<img>Image2</img>" [1]
有更好的选择吗?
我想这是不是真的HTML吗? –
Ehhh,在给出答案后不要改变你的问题。这使得其他读者不在。我试图在评论中给出最新的答案。 –
对不起:(忘了添加我需要的输出 –