How to get the file extension from a url?

后端 未结 5 994
小蘑菇
小蘑菇 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:30

    This works for files with query string

    file = 'http://recyclewearfashion.com/stylesheets/page_css/page_css_4f308c6b1c83bb62e600001d.css?1343074150'
    File.extname(URI.parse(file).path) # => '.css'
    

    also returns "" if file has no extension

提交回复
热议问题