Jump to content

Extract file extension: Difference between revisions

→‎Task: improve formatting and wording
(→‎{{header|Forth}}: Add Fortran.)
(→‎Task: improve formatting and wording)
Line 1:
{{draft task}}
 
{{task heading}}
Write a program that takes one string argument representing the path to a file and returns the file's extension, or the null string if the file path has no extension.
 
Write a function or program that
An extension appears after the last period in the file name and consists of one or more letters or numbers.
* takes one string argument representing the path/URL to a file
* returns the file's extension, or an empty string if it has no extension.
 
{{task heading|Details}}
Show here the action of your routine on the following examples:
 
* An extension appears after the last period in the file's name, and consists of one or more letters or numbers.
# picture.jpg returns .jpg
* The file name is separated from preceding directory parts, if any, by a forward slash.
# <nowiki>http://mywebsite.com/picture/image.png</nowiki> returns .png
 
# myuniquefile.longextension returns .longextension
{{task heading|Test cases}}
# IAmAFileWithoutExtension returns an empty string ""
 
# /path/to.my/file returns an empty string as the period is in the directory name rather than the file
{| class="wikitable"
# file.odd_one returns an empty string as an extension (by this definition), cannot contain an underscore.
|-
<br><br>
! Input
! Output
! Comment
|-
| <code>picture.jpg</code>
| <code>.jpg</code>
|
|-
#| <code><nowiki>http://mywebsite.com/picture/image.png</nowiki> returns .png</code>
| <code>.png</code>
|
|-
#| <code>myuniquefile.longextension returns .longextension</code>
| <code>.longextension</code>
|
|-
#| <code>IAmAFileWithoutExtension returns an empty string ""</code>
| <code></code>
| ''empty string''
|-
| <code>/path/to.my/file</code>
| <code></code>
# /path/to.my/file returns an| ''empty string, as the period is in the directory name rather than the file name''
|-
| <code>file.odd_one</code>
| <code></code>
# file.odd_one returns an| ''empty string, as an extension (by this definition), cannot contain an underscore.''
|}
 
<hr>
 
=={{header|ALGOL 68}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.