2011-11-22 87 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