日期:2014-05-17  浏览次数:21026 次

c# 寻找字符串中指定 字段 替换
string a1={ <td style="TEXT-ALIGN: center; HEIGHT: 40px; BORDER-TOP: red 1px solid; BORDER-RIGHT: red 1px solid"><IMG style="CURSOR: hand" id=0.1869366964525968 onclick=openyz(0.1869366964525968,201211189789) name=0.1869366964525968 alt="" src="/images/123.gif">&nbsp;</td>
                  <td style="TEXT-ALIGN: center; HEIGHT: 40px; BORDER-TOP: red 1px solid; BORDER-RIGHT: red 1px solid"><IMG style="CURSOR: hand" id=0.5159706003032625 onclick=openyz(0.5159706003032625,201211187808) name=0.5159706003032625 alt="" src="/images/123.gif">&nbsp;</td> 
<td style="TEXT-ALIGN: center; HEIGHT: 40px; BORDER-TOP: red 1px solid; BORDER-RIGHT: red 1px solid"><IMG style="CURSOR: hand" id=0.1869366964525968 onclick=openyz(0.1869366964525968,201211189791) name=0.1869366964525238 alt="" src="/images/123.gif">&nbsp;</td> }
string a2= "201211187808";
如上两个字符串   在 a1 中 查找 a2  如果相等  则将 后面的  src="/images/123.gif" 替换为 src="/images/1234.gif"

各位大虾 请赐教

------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string a1 = @"<td style=""TEXT-ALIGN: center; HEIGHT: 40px; BORDER-TOP: red 1px solid; BORDER-RIGHT: red 1px solid""><IMG style=""CURSOR: hand"" id=0.1869366964525968 onclick=openyz(0.1869366964525968,201211189789) name=0.1869366964525968 alt="""" src=""/images/123.gif"">&nbsp;</td>
                  <td style=""TEXT-ALIGN: center; HEIGHT: 40px; BORDER-TOP: red 1px solid; BORDER-RIGHT: red 1px solid""><IMG style=""CURSOR: hand"" id=0.5159706003032625 onclick=openyz(0.5159706003032625,201211187808) name=0.5159706003032625 alt="""" src=""/images/123.gif"">&nbsp;</td> 
<td style=""TEXT-ALIGN: center; HEIGHT: 40px; BORDER-TOP: red 1px solid; BORDER-RIGHT: red 1px solid""><IMG style=""CURSOR: hand"" id=0.1869366964525968 onclick=openyz(0.1869366964525968,201211189791) name=0.1869366964525238 alt="""" src=""/images/123.gif"">&nbsp;</td>";