Extract file extension: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: changed comments and whitespace. |
→{{header|Perl 6}}: use the new test-cases, and compare output to the built-in .extension method |
||
Line 10: | Line 10: | ||
If your programming language (or standard library) has built-in functionality for extracting a filename extension, show how it would be used |
If your programming language (or standard library) has built-in functionality for extracting a filename extension, show how it would be used and how exactly its behavior differs from this specification. |
||
{{task heading|Specification}} |
{{task heading|Specification}} |
||
Line 31: | Line 31: | ||
| |
| |
||
|- |
|- |
||
| <code> |
| <code>CharacterModel.3DS</code> |
||
| <code>. |
| <code>.3DS</code> |
||
| |
| |
||
|- |
|- |
||
Line 801: | Line 801: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
The built-in <code> |
The built-in <code>IO::Path</code> class has an <code>.extension</code> method: |
||
<lang perl6>say $path.IO.extension;</lang> |
|||
Contrary to this task's specification, it |
|||
* doesn't include the dot in the output |
* doesn't include the dot in the output |
||
* doesn't restrict |
* doesn't restrict the extension to letters and numbers. |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
}</lang> |
}</lang> |
||
Testing: |
Testing: |
||
<lang perl6> |
<lang perl6>printf "%-35s %-11s %-12s\n", $_, extension($_).perl, $_.IO.extension.perl |
||
for < |
|||
'mywebsite.com/picture/image.png', |
|||
http://example.com/download.tar.gz |
|||
CharacterModel.3DS |
|||
'myuniquefile.longextension', |
|||
.desktop |
|||
'IAmAFileWithoutExtension', |
|||
document |
|||
'/path/to.my/file', |
|||
document.txt_backup |
|||
/etc/pam.d/login |
|||
;</lang> |
>;</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
http://example.com/download.tar.gz ".gz" "gz" |
|||
mywebsite.com/picture/image.png -> ".png" |
|||
CharacterModel.3DS ".3DS" "3DS" |
|||
http://mywebsite.com/picture/image.png -> ".png" |
|||
.desktop ".desktop" "desktop" |
|||
myuniquefile.longextension -> ".longextension" |
|||
document "" "" |
|||
IAmAFileWithoutExtension -> "" |
|||
document.txt_backup "" "txt_backup" |
|||
/path/to.my/file -> "" |
|||
/etc/pam.d/login "" "" |
|||
file.odd_one -> "" |
|||
</pre> |
</pre> |
||