我想把下面的的ip地址替换为对应的地址string allhtm="<P><FONT face="宋体">方式的方式的192.168.1.1我啊66</FONT></P><P><FONT face="宋体">220.220.6.1哈哈哈日442</FONT></P>";
string   pattern1  =   @"(\d+).(\d+).(\d+).1";
//有一个ip对应的替换类已经通过了测试
//ipchaxun i=new ipchaxun();
//string ip="117.27.219.1";
//string dizhi=i.getplacename(ip);

//下面的这句我写通不过
string kk=Regex.Replace(allhtm,pattern1,i.getplacename($1.$2.$3);,RegexOptions.RightToLeft);
请问各位高手最后的这句要怎么写呢或者用什么方法

解决方案 »

  1.   

    Replace可以以委托为参数,但i.getplacename($1.$2.$3)是方法,你需要先定义一个委托Regex rg = new Regex(pattern1,RegexOptions.RightToLeft);
    MatchEvaluator myEvaluator = new MatchEvaluator(i.getplacename);
    richTextBox1.Text = rg.Replace(allhtm, myEvaluator);
      

  2.   

    string kk=Regex.Replace(allhtm,pattern1,i.getplacename($1.$2.$3),RegexOptions.RightToLeft);
      

  3.   


    string allhtm = "<P><FONT face=\"宋体\">方式的方式的192.168.1.1我啊66</FONT></P><P><FONT face=\"宋体\">220.220.6.1哈哈哈日442</FONT></P>";
                string pattern1 = @"(\d+\.\d+\.\d+\.1)";
                allhtm = Regex.Replace(allhtm, pattern1, i.getplacename("$0"));