Extract file extension: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Minor tidy)
No edit summary
Line 1,173:
/etc/pam.d/login (empty string)
</pre>
 
=={{header|FreePascal}}==
<syntaxhighlight lang="pascal">Program Extract_file_extension;
 
{FreePascal has the built-in function ExtractFileExt which returns the file extension.
* it does need charachters before the period to return the proper extension and it returns
* the extension including the period}
 
Uses character,sysutils;
 
Const arr : array of string = ('http://example.com/download.tar.gz','CharacterModel.3DS','.desktop',
'document','document.txt_backup','/etc/pam.d/login');
 
Function extractextension(fn: String): string;
Var
i: char;
Begin
fn := 'prefix' + fn; {add charachters before the period}
fn := ExtractFileExt(fn);
delete(fn,1,1); {remove the period}
For i In fn Do
If Not IsLetterOrDigit(i) Then exit('');
extractextension := fn;
End;
 
Var i : string;
Begin
For i In arr Do
writeln(i:35,' -> ',extractextension(i))
End.
</syntaxhighlight>
 
{{out}}
<pre>
http://example.com/download.tar.gz -> gz
CharacterModel.3DS -> 3DS
.desktop -> desktop
document ->
document.txt_backup ->
/etc/pam.d/login ->
</pre>
 
 
 
=={{header|Frink}}==