Extract file extension: Difference between revisions
Content deleted Content added
m →{{header|Lua}}: (shortened) |
m →{{header|REXX}}: changed/added comments and whitespace, changed indentations. |
||
Line 857: | Line 857: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Using this paraphrased Rosetta Code task's definition that: |
|||
⚫ | |||
a legal file extension ''only'' consists of mixed-case Latin letters and/or decimal digits. |
|||
⚫ | |||
⚫ | |||
parse arg fID /*obtain any optional arguments from CL*/ |
|||
@.= /*define default value for the @ array.*/ |
|||
parse arg fID /*obtain any optional arguments from CL*/ |
|||
if fID\=='' then @.1 = fID /*use the filename from the C.L. */ |
|||
⚫ | |||
@.1 = 'picture.jpg' |
@.1 = 'picture.jpg' |
||
@.2 = 'http://mywebsite.com/pictures/image.png' |
@.2 = 'http://mywebsite.com/pictures/image.png' |
||
Line 871: | Line 873: | ||
end |
end |
||
do j=1 while @.j\==''; x= /*process (all of) the file name(s). */ |
do j=1 while @.j\==''; x= /*process (all of) the file name(s). */ |
||
p=lastpos(.,@.j) /*find the last position of a period. */ |
p=lastpos(.,@.j) /*find the last position of a period. */ |
||
if p\==0 then x=substr(@.j,p+1) /*Found a dot? Then get stuff after it*/ |
if p\==0 then x=substr(@.j, p+1) /*Found a dot? Then get stuff after it*/ |
||
if \datatype(x,'A') then x= /*is it upper/lowercase letters|digits?*/ |
if \datatype(x, 'A') then x= /*is it upper/lowercase letters|digits?*/ |
||
if x=='' then x=" [null]" /*use a better name for a "null". */ |
if x=='' then x= " [null]" /*use a better name for a "null". */ |
||
else x=. || x /*prefix the extension with a period. */ |
else x= . || x /*prefix the extension with a period. */ |
||
say 'file |
say 'file extension=' left(x, 20) "for file name=" @.j |
||
⚫ | |||
end /*j*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
<pre> |
<pre> |
||
file |
file extension= .jpg for file name= picture.jpg |
||
file |
file extension= .png for file name= http://mywebsite.com/pictures/image.png |
||
file |
file extension= .longextension for file name= myuniquefile.longextension |
||
file |
file extension= [null] for file name= IAmAFileWithoutExtension |
||
file |
file extension= [null] for file name= /path/to.my/file |
||
file |
file extension= [null] for file name= file.odd_one |
||
</pre> |
</pre> |
||