我现数据库中存的内容是
恭恭敬敬恭恭敬敬<img alt="" src="/UserFiles/0001.jpg" />工   
如上的内容
现在我想把其中的<img alt="" src="/UserFiles/0001.jpg" />里面的图片地址取出来单位使用,而且在显示内容时,却不显示这个图下。
就是说我把图下从这个内容中取出来,显示在上面。而且内容显示中不显示这个图下
就是取出后,用replace把<img alt="" src="/UserFiles/0001.jpg" />变成空
这个怎么做啊。
最好用C#代码

解决方案 »

  1.   

    用正则作        
    string s = "恭恭敬敬恭恭敬敬 <img alt=\"\" src=\"/UserFiles/0001.jpg\" />工 ";        System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("<img[\\S\\s]*?>");        s = reg.Replace(s, "");
      

  2.   

    举例:string strSource = @"恭恭敬敬恭恭敬敬 <img alt="""" src=""/UserFiles/0001.jpg"" />工  "
    string strImgUrl = Regex.Match(strSource, @"src=""/[\s\S]+?"" />").ToString();//取得图片地址
    strSource = Regex.Replace(strSource,@"<img[\s\S]+?>","");//去掉图片标签
      

  3.   


    string strSource = @"恭恭敬敬恭恭敬敬 <img alt="""" src=""/UserFiles/0001.jpg"" />工  "
    string strImgUrl = Regex.Match(strSource, @"src=""[\s\S]+?"" />").ToString();//取得图片地址
    strSource = Regex.Replace(strSource,@"<img[\s\S]+?>","");//去掉图片标签这样你试试
      

  4.   

    错误 1 无法使用实例引用来访问成员“System.Text.RegularExpressions.Regex.Match(string, string)”;请改用类型名来限定它 F:\WebFrom\bakData\bakData\WebForm2.aspx.cs 27 32 bakData
      

  5.   

    要改一下:string strSource = @"恭恭敬敬恭恭敬敬 <img alt="""" src=""/UserFiles/0001.jpg"" />工  ";
    string strImgUrl = Regex.Match(strSource, @"src=""/([\s\S]+?)"" />").Groups[1].Value;//取得图片地址
    strSource = Regex.Replace(strSource,@"<img[\s\S]+?>","");//去掉图片标签
      

  6.   

    不行啊,还是报同样的错误啊
    System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(" <img[\\S\\s]*?>");
    string strSource = @"恭恭敬敬恭恭敬敬 <img alt="""" src=""/UserFiles/0001.jpg"" />工  ";
                string strImgUrl = reg.Match(strSource, @"src=""/([\s\S]+?)"" />").Groups[1].Value;//取得图片地址
                strSource = reg.Replace(strSource, @"<img[\s\S]+?>", "");//去掉图片标签            Response.Write(strImgUrl + "<br>");
                Response.Write(strSource);这是我的代码
      

  7.   


    string strhtml="恭恭敬敬恭恭敬敬 <img alt="""" src=""/UserFiles/0001.jpg"" />工"
    string strPattern = @"src=""/([\s\S]+?)"" />";
                    MatchCollection mc = Regex.Matches(strHtml, strPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
     foreach (Match m in mc)
                    {
                  strSource = m.Groups[0].Value.ToString().Trim();
                    }
      

  8.   

    不用实例化一个Regex实例,Regex类本身具有静态方法Match和Replace,
    你先using System.Text.RegularExpressions;
    再按照我的代码写就可以了