How to get the file extension from a url?

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

    url = 'http://www.example.com/asdf123.gif'
    extension = url.split('.').last
    

    Will get you the extension for a URL(in the most simple manner possible). Now, for output formatting:

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

提交回复
热议问题