string url = "http://pic.aa.com/bb/200812/20081217174617355.jpg";
  
若结尾是jpg或JPG,则变成"http://pic.aa.com/bb/200812/20081217174617355_sml.jpg";
            若是gif,则变成"http://pic.aa.com/bb/200812/20081217174617355_sml.gif";
            若是png,则变成"http://pic.aa.com/bb/200812/20081217174617355_sml.png";
            要求用正则

解决方案 »

  1.   

    string url = "http://pic.aa.com/bb/200812/20081217174617355.jpg";
    int count = url.IndexOf(".jpg");
    url = url.Substring(0, count) + "_sml" + ".jpg";
    Console.WriteLine(url);
      

  2.   

    要求用正则.string url = "http://pic.aa.com/bb/200812/20081217174617355.jpg";
    int count = url.IndexOf(".jpg");
    url = url.Substring(0, count) + "_sml" + ".jpg";
    Console.WriteLine(url);int count = url.IndexOf(".gif");
    url = url.Substring(0, count) + "_sml" + ".gif";
    Console.WriteLine(url);......
    上面的写法都会
      

  3.   

    唉。string url = "http://pic.aa.com/bb/200812/20081217174617355.jpg";
    url = Regex.Replace(url,@"(?i)\.jpg","_sml$0");
    Console.WriteLine(url);
      

  4.   

    注:string url = "http://pic.aa.com/bb/200812/20081217174617355.jpg"; 由于允许上传的图片类型很多,结属的扩展名不确定,可能是png,可能是PNG,可能是gif,可能是bmp,所以用正则匹配会更好一些.
      

  5.   

    全的string url = "http://pic.aa.com/bb/200812/20081217174617355.GIF";
    url = Regex.Replace(url,@"(?i)\.(jpg|jpeg|gif|png)","_sml$0");
    Console.WriteLine(url);
      

  6.   


    //楼主是不是想将图片的名字中的非数字的字符去掉阿?
    string str = "http://pic.aa.com/bb/200812/20081217174617355_sml.jpg";
    string output = Regex.Replace(str,@"(?i)[^\d]+(?=\.(jpg|gif|png))","");