File extension is in extensions list: Difference between revisions

Content added Content deleted
Line 623: Line 623:
"foo.C++" does not have an admissible file extension
"foo.C++" does not have an admissible file extension
"document.pdf" does not have an admissible file extension</lang>
"document.pdf" does not have an admissible file extension</lang>


=={{header|Objeck}}==
<lang objeck>
class FileExtension {
function : Main(args : String[]) ~ Nil {
files := ["MyData.a##", "MyData.tar.Gz", "MyData.gzip",
"MyData.7z.backup", "MyData...", "MyData", "MyData_v1.0.tar.bz2", "MyData_v1.0.bz2"];
exts := ["zip", "rar", "7z", "gz", "archive", "A##", "tar.bz2"];
each(i : files) {
HasExt(files[i], exts);
};
}

function : HasExt(file : String, exts : String[]) ~ Nil {
full_file := file->ToLower();
each(i : exts) {
full_ext := ".";
full_ext += exts[i]->ToLower();
if(full_file->EndsWith(full_ext)) {
IO.Console->Print(file)->Print(" has extension \"")->Print(exts[i])->PrintLine("\"");
return;
};
};

IO.Console->Print(file)->PrintLine(" does not have an extension in the list");
}
}</lang>

{{out}}
<pre>MyData.a## has extension "A##"
MyData.tar.Gz has extension "gz"
MyData.gzip does not have an extension in the list
MyData.7z.backup does not have an extension in the list
MyData... does not have an extension in the list
MyData does not have an extension in the list
MyData_v1.0.tar.bz2 has extension "tar.bz2"
MyData_v1.0.bz2 does not have an extension in the list</pre>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==