2011-11-22 136 views
0

前添加锚标记我有一个字符串:图片标签

string explanation= "Which of the following are associated with ependymitis " + 
    "<img id='id=47148;displayStyle=Simple;width=100;height=62;loop=False;' " + 
     "isMaintainAspectRatio=True "+ 
    "src='../Admin/GetImage.ashx?id=240648' alt='Image4' width='100' height='62' " + 
    "href='../Admin/GetImage.ashx?id=240648'/><br />"; 

我想<img>标签之前添加<a></a>标签。我们如何解释<img>标签?

+0

[img id ='id = 47148; displayStyle = Simple; width = 100; height = 62; loop = False; isMaintainAspectRatio = True]这个乱码是什么?这甚至不接近适当的图像标签。 – Graham

+0

你的问题不清楚。你是否试图将这个img“规范”变成可点击的图像链接?你显然也在对这个字符串做额外的处理,因为它看起来不像我见过的没有img标签。 –

+0

你有没有检出HtmlAgilityPack - http://htmlagilitypack.codeplex.com/? –

回答

0

可以使用String.Replace方法:

explanation.Replace("<img", "<a></a><img"); 

或者,如果你想只更换<img>标签(不知道我应该了解你的问题)的第一次出现,看看这个thread

+0

真正回答正在询问的内容。 – bunglestink

+0

我不认为这充分考虑了问题的背景 - 虽然OP表示他们希望在“”标签之前添加“”标签,但“”无效,“”右标记不存在于标记中。 –

+0

@AlexNorcliffe:那不是问题,是吗?也许OP在'Replace'操作后知道他想对字符串做什么。 – Otiel