Extract file extension: Difference between revisions

no edit summary
No edit summary
Line 80:
/etc/pam.d/login ->
</pre>
 
=={{header|Ada}}==
<lang Ada>with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
use Ada.Strings;
with Ada.Characters.Handling; use Ada.Characters.Handling;
 
procedure Main is
function extension (S : in String) return String is
P_Index : Natural;
begin
P_Index :=
Index (Source => S, Pattern => ".", From => S'Last, Going => Backward);
if P_Index = 0 then
return "";
else
for C of S (P_Index + 1 .. S'Last) loop
if not Is_Alphanumeric (C) then
return "";
end if;
end loop;
return S (P_Index .. S'Last);
end if;
end extension;
F1 : String := "http://example.com/download.tar.gz";
F2 : String := "CharacterModel.3DS";
F3 : String := ".desktop";
F4 : String := "document";
F5 : String := "document.txt_backup";
F6 : String := "/etc/pam.d/login:";
begin
Put_Line (F1 & " -> " & extension (F1));
Put_Line (F2 & " -> " & extension (F2));
Put_Line (F3 & " -> " & extension (F3));
Put_Line (F4 & " -> " & extension (F4));
Put_Line (F5 & " -> " & extension (F5));
Put_Line (F6 & " -> " & extension (F6));
end Main;
</lang>
{{output}}
<pre>
http://example.com/download.tar.gz -> .gz
CharacterModel.3DS -> .3DS
.desktop -> .desktop
document ->
document.txt_backup ->
/etc/pam.d/login: ->
</pre>
 
 
=={{header|ALGOL 68}}==
82

edits