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# I would do:
string.format("http://www.example.com/{0}.{1}", filename, extension);
String extension = uri. substring(url. lastIndexOf(".") + 1);
A URL file is a shortcut that points to a specific Uniform Resource Locator. When you double-click a URL file, your computer accesses the URL the file contains. URL files most often contain https: web addresses and are used to access web pages. However, URL files can also contain mailto:, tel:, file:, or other URLs.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With