class Program {
static string[] HouZhuis = new string[] { ".png", ".gif", ".jpg" };
static void Main(string[] args)
{
string startStr = "src=\"";
string textStr = "img src=\"Blog/Lists/Photos/030912_0837_Testa1.png\" alt=\"\" style=\"width:371px;height:220px\"";
int startIndex = textStr.IndexOf(startStr) + startStr.Length;
if (startIndex < 0)
{
Console.WriteLine("未找到图片路径"); return;
}
int endIndex = textStr.IndexOf("\"", startIndex);
string src = textStr.Substring(startIndex, endIndex - startIndex);
int dianIndex = src.LastIndexOf(".");
if (dianIndex < 0)
{
Console.WriteLine("不是合法的路径");
return;
}
string houzhuiStr = src.Substring(dianIndex, src.Length - dianIndex);
if (!HouZhuis.Contains(houzhuiStr))
{
Console.WriteLine("不是合法的路径"); return;
}
Console.WriteLine("图片路径:" + src);
}
}
}