代码之家  ›  专栏  ›  技术社区  ›  leora Matt Lacey

如何从图像url中解析出图像名

  •  9
  • leora Matt Lacey  · 技术社区  · 14 年前

    http://www.google.com/image1.jpg
    http://www.google.com/test/test23/image1.jpg
    

    我想得到:

    image1.jpg
    

    在C#里最好的方法是什么?

    4 回复  |  直到 7 年前
        1
  •  25
  •   Fredrik Hedblad    14 年前
    string fileName = Path.GetFileName(@"http://www.google.com/test/test23/image1.jpg");
    
        2
  •  5
  •   rerun    14 年前

    只要确定它是一个图像文件,就可以使用path类。

    System.io.path.GetFilenAME

        3
  •  1
  •   Lorenzo OnoSendai    14 年前
    public static void doSomething() {
        string url = "http:\\www.google.com\image1.jpg";
        string imageFileName = url.Substring( url.LastIndexOf( '\\' ) + 1 );
    }
    
        4
  •  1
  •   brumScouse    14 年前

    不是最好的,但肯定是一种方法

    url = "blahblah\image1.jpg"
    
    string imageName  = url.substring(url.lastindexof("\") + 1);