How to get the file extension from a url?

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

    Use File.extname

    File.extname("test.rb")         #=> ".rb"
    File.extname("a/b/d/test.rb")   #=> ".rb"
    File.extname("test")            #=> ""
    File.extname(".profile")        #=> ""
    

    To format the string

    "http://www.example.com/%s.%s" % [filename, extension]
    

提交回复
热议问题