Extract file extension: Difference between revisions
→{{header|Java}}
m (→{{header|C++}}: Fixed formatting and code output) |
|||
Line 1,385:
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.io.File;
public static void main(String[] args) {▼
<syntaxhighlight lang="java">
String[] filenames = { "http://example.com/download.tar.gz",▼
String[] strings = {
for (String string : strings)
System.out.println(extractExtension(string));
}
static String
/* we can use the 'File' class to
File file = new File(string);
String filename = file.getName();
if (idx != -1) {▼
int
if (tmp.matches("\\.[a-zA-Z0-9]+")) {▼
String
/* and use a regex to match only
▲ }
}
return "";
▲}</syntaxhighlight>
}
</syntaxhighlight>
{{Out}}
<pre>
.gz
.3DS
.desktop
▲document.txt_backup -> null
▲/etc/pam.d/login -> null</pre>
</pre>
=={{header|javascript}}==
|