Extract file extension: Difference between revisions

no edit summary
(Added XPL0 example.)
No edit summary
Line 2,621:
/etc/pam.d/login -> </pre>
Note: the task's description seems wrong to me; on a Unix machine, files beginning with "." are treated as hidden files (eg. in ls) and the suffix can be considered to be empty. As opposed to "a.desktop".
 
=={{header|SNOBOL4}}==
{{works with|SNOBOL4, SPITBOL for Linux}}
<lang SNOBOL4>
* Program: extract_extension.sbl
* To run: sbl extract_extension.sbl
* Description: Extract file extension
* Comment: Tested using the Spitbol for Linux version of SNOBOL4
 
filenames =
+ "http://example.com/download.tar.gz,"
+ "CharacterModel.3DS,"
+ ".desktop,"
+ "document,"
+ "document.txt_backup,"
+ "/etc/pam.d/login"
 
epat = ((span(&lcase &ucase '0123456789') ".") | "") . ext
p0
filenames ? (break(',') . s ',') | (len(1) rem) . s = "" :f(end)
reverse(s) ? epat
ext = reverse(ext)
output = ""
output = "Extension from file '" s "' is '" ext "'"
:(p0)
END
</lang>
{{out}}
<pre>
Extension from file 'http://example.com/download.tar.gz' is '.gz'
 
Extension from file 'CharacterModel.3DS' is '.3DS'
 
Extension from file '.desktop' is '.desktop'
 
Extension from file 'document' is ''
 
Extension from file 'document.txt_backup' is ''
 
Extension from file '/etc/pam.d/login' is ''
</pre>
 
=={{header|Standard ML}}==
Anonymous user