类似如下
[:2:]要替换成“image\\2.gif”
[:9:]要替换成“image\\9.gif”
[:11:]要替换成“image\\11.gif”

解决方案 »

  1.   

    string inputStr="[:2:]";
    inputStr=inputStr.Replace("[:",@"image\\");
    inputStr=inputStr.Replace(":]",".gif");
      

  2.   

    先用正则表达式取出数字
    \[\:(.*)\:\]
    然后拼出来
    "image\\"+数字+".gif"
      

  3.   

    shrinerain(圣影雨) 的办法当然是可以,不过我就是想用正则表达式的思路实现一下,大家接着贴,分不够我可以加的。
      

  4.   

    re mathsword(梦在流浪),我这里是绑定的啦,最好是用Regex.Replace直接一句写出来,简练一点最好
      

  5.   

    string str="[:11:]";
    System.Text .RegularExpressions .Regex regx=new System.Text.RegularExpressions.Regex (@"\[\:(\d+)\:\]");
    Response.Write (regx.Replace (str,@"image\\$1.gif"));
      

  6.   

    同意 vivianfdlpw() 
    简洁点就是:
    Regex.Replace(str, @"\[\:(\d+))\:\]"), @"image\\$1.gif",RegexOptions.IgnoreCase);
      

  7.   

    string a="[:11:]A[:15:]B[:13:]";
    a=System.Text.RegularExpressions.Regex.Replace(a,@"\[:","image\\");
    a=System.Text.RegularExpressions.Regex.Replace(a,@":\]",".gif");