Extract file extension: Difference between revisions
Content added Content deleted
(Added solution for Action!) |
|||
Line 79: | Line 79: | ||
document.txt_backup -> |
document.txt_backup -> |
||
/etc/pam.d/login -> |
/etc/pam.d/login -> |
||
</pre> |
|||
=={{header|Action!}}== |
|||
{{libheader|Action! Tool Kit}} |
|||
<lang Action!>INCLUDE "D2:CHARTEST.ACT" ;from the Action! Tool Kit |
|||
PROC FileExt(CHAR ARRAY path,ext) |
|||
BYTE pos,c |
|||
pos=path(0) |
|||
ext(0)=0 |
|||
WHILE pos>0 |
|||
DO |
|||
c=path(pos) |
|||
IF c='. THEN |
|||
EXIT |
|||
ELSEIF IsDigit(c)=0 AND IsAlpha(c)=0 THEN |
|||
RETURN |
|||
FI |
|||
pos==-1 |
|||
OD |
|||
IF pos=0 THEN |
|||
RETURN |
|||
FI |
|||
SCopyS(ext,path,pos,path(0)) |
|||
RETURN |
|||
PROC Test(CHAR ARRAY path) |
|||
CHAR ARRAY ext(10) |
|||
FileExt(path,ext) |
|||
PrintF("""%S"":%E""%S""%E%E",path,ext) |
|||
RETURN |
|||
PROC Main() |
|||
Put(125) PutE() ;clear the screen |
|||
Test("http://example.com/download.tar.gz") |
|||
Test("CharacterModel.3DS") |
|||
Test(".desktop") |
|||
Test("document") |
|||
Test("document.txt_backup") |
|||
Test("/etc/pam.d/login") |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Extract_file_extension.png Screenshot from Atari 8-bit computer] |
|||
<pre> |
|||
"http://example.com/download.tar.gz": |
|||
".gz" |
|||
"CharacterModel.3DS": |
|||
".3DS" |
|||
".desktop": |
|||
".desktop" |
|||
"document": |
|||
"" |
|||
"document.txt_backup": |
|||
"" |
|||
"/etc/pam.d/login": |
|||
"" |
|||
</pre> |
</pre> |
||