Extract file extension: Difference between revisions
Content deleted Content added
→{{header|Forth}}: Add Fortran. |
→Task: improve formatting and wording |
||
Line 1:
{{draft task}}
{{task heading}}
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}}
▲* An extension appears after the last period in the file's name, and consists of one or more letters or numbers.
* 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.▼
|-
! Input
! Output
! Comment
|-
| <code>picture.jpg</code>
| <code>.jpg</code>
|
|-
| <code>.png</code>
|
|-
| <code>.longextension</code>
|
|-
| <code></code>
| ''empty string''
|-
| <code>/path/to.my/file</code>
| <code></code>
▲
|-
| <code>file.odd_one</code>
| <code></code>
▲
|}
<hr>
=={{header|ALGOL 68}}==
|