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?
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.
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.
GetFileNameWithoutExtension(ReadOnlySpan<Char>) Returns the file name without the extension of a file path that is represented by a read-only character span.
Use std.path.extension
. e.g.
assert("file.foo".extension == ".foo");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With