How to get the file extension from a url?

后端 未结 5 945
小蘑菇
小蘑菇 2021-02-03 20:02

New to ruby, how would I get the file extension from a url like:

http://www.example.com/asdf123.gif

Also, how would I format this string, in c#

5条回答
  •  一向
    一向 (楼主)
    2021-02-03 20:05

    I realize this is an ancient question, but here's another vote for using Addressable. You can use the .extname method, which works as desired even with a query string:

     Addressable::URI.parse('http://www.example.com/asdf123.gif').extname # => ".gif"
     Addressable::URI.parse('http://www.example.com/asdf123.gif?foo').extname # => ".gif"
    

提交回复
热议问题