我现数据库中存的内容是
恭恭敬敬恭恭敬敬<img alt="" src="/UserFiles/0001.jpg" />工
如上的内容
现在我想把其中的<img alt="" src="/UserFiles/0001.jpg" />里面的图片地址取出来单位使用,而且在显示内容时,却不显示这个图下。
就是说我把图下从这个内容中取出来,显示在上面。而且内容显示中不显示这个图下
就是取出后,用replace把<img alt="" src="/UserFiles/0001.jpg" />变成空
这个怎么做啊。
最好用C#代码
恭恭敬敬恭恭敬敬<img alt="" src="/UserFiles/0001.jpg" />工
如上的内容
现在我想把其中的<img alt="" src="/UserFiles/0001.jpg" />里面的图片地址取出来单位使用,而且在显示内容时,却不显示这个图下。
就是说我把图下从这个内容中取出来,显示在上面。而且内容显示中不显示这个图下
就是取出后,用replace把<img alt="" src="/UserFiles/0001.jpg" />变成空
这个怎么做啊。
最好用C#代码
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, "");
string strImgUrl = Regex.Match(strSource, @"src=""/[\s\S]+?"" />").ToString();//取得图片地址
strSource = Regex.Replace(strSource,@"<img[\s\S]+?>","");//去掉图片标签
string strSource = @"恭恭敬敬恭恭敬敬 <img alt="""" src=""/UserFiles/0001.jpg"" />工 "
string strImgUrl = Regex.Match(strSource, @"src=""[\s\S]+?"" />").ToString();//取得图片地址
strSource = Regex.Replace(strSource,@"<img[\s\S]+?>","");//去掉图片标签这样你试试
string strImgUrl = Regex.Match(strSource, @"src=""/([\s\S]+?)"" />").Groups[1].Value;//取得图片地址
strSource = Regex.Replace(strSource,@"<img[\s\S]+?>","");//去掉图片标签
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);这是我的代码
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();
}
你先using System.Text.RegularExpressions;
再按照我的代码写就可以了