filenameSetext

fnstring filenameSetext(string filename, string ext) @trusted

Sets or replaces the extension of a filename.

If the filename already has an extension, it is replaced. Otherwise, the new extension is appended.

Parameters

filenameOriginal filename
extNew extension (should include the leading dot)

Returns

The filename with the new extension.

Example:

assert(filenameSetext("file.txt", ".doc") == "file.doc");
assert(filenameSetext("file", ".txt") == "file.txt");