First, find the location of the first
Then, separate spaces to obtain the attributes and attribute values of the image. The extracted SRC value is the image address.
CodeAs follows:
Copy code The Code is as follows: // <summary>
/// Obtain the image address in the text
/// </Summary>
/// <Param name = "content"> content </param>
/// <Returns> address string </returns>
Public static string getimageurl (string content)
{
Int mouse = 0;
Int cat = 0;
String imagelabel = "";
String imgsrc = "";
String [] attributes;
Do // get the connection of the first image as the main Image
{
Cat = content. indexof ("Mouse = content. indexof ('>', CAT );
Imagelabel = content. substring (CAT, mouse-cat); // Image Tag
Attributes = imagelabel. Split (''); // separate image attributes
Foreach (string temp_attributes in attributes) // obtain the image address attribute
If (temp_attributes.indexof ("src")> = 0)
{
Imgsrc = temp_attributes.tostring ();
Break;
}
Imgsrc = imgsrc. substring (imgsrc. indexof ('"') + 1, imgsrc. lastindexof ('"')-imgsrc. indexof ('"')-1); // extract the address from the cluster address attribute
} While (imgsrc = "" & CAT> 0 );
Return (imgsrc );
}