今天在论坛上看到有朋友需要取得tag的值,很多人回复都是以正则来取。Insus.NET想了一下,它的字符串即是xml的节点。
只即需要转为xml之后,就可以很容易取得src的值:
- string str="<IMG height=\"372\" alt=\"aa\" src=\"\" width=\"594\" border=\"0\" />";
- XmlDocument xDoc = new XmlDocument();
- xDoc.Load(new System.IO.MemoryStream(System.Text.Encoding.GetEncoding ("UTF-8").GetBytes (str)));
- XmlNodeList xNode = xDoc.SelectNodes("//IMG");
- {
- for (int i = 0; i < xNode.Count; i++)
- {
- Response.Write ( xNode[i].Attributes["src"].Value);
- }
- }
