Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most concise way to extract file name extension

Tags:

string

d

Which would be the most concise way to extract the extension from a filename string (including and not including the last dot .) in the D language? Right now I'm using lastIndexOf(). Is there a cleaner/preferable way?

like image 965
glampert Avatar asked Jun 24 '14 04:06

glampert


People also ask

How do I separate filenames and extensions?

The function splitext() in os. path allows you to separate the root and extension of a specified file path. A tuple made up of the root string and the extension string is the function's output.

How do I extract just the filename?

To extract filename from the file, we use “GetFileName()” method of “Path” class. This method is used to get the file name and extension of the specified path string.

How can I find the file name without extension?

GetFileNameWithoutExtension(ReadOnlySpan<Char>) Returns the file name without the extension of a file path that is represented by a read-only character span.


1 Answers

Use std.path.extension. e.g.

assert("file.foo".extension == ".foo");
like image 93
Jonathan M Davis Avatar answered Oct 18 '22 03:10

Jonathan M Davis