Function std.path.setExtension
Returns a string containing the path given by
, but where
the path
extension
has been set to
.
ext
If the filename already has an extension
, it is replaced. If not, the
extension
is simply appended to the filename. Including a leading dot
in
is optional.
ext
If the extension
is empty, this function is equivalent to
stripExtension
.
This function normally allocates a new string (the possible exception
being the case when path
is immutable and doesn't already have an
extension
).
Prototypes
immutable(Unqual!C1)[] setExtension(C1, C2)( C1[] path, C2[] ext ) if (isSomeChar!C1 && !is(C1 == immutable) && is(Unqual!C1 == Unqual!C2)); immutable(C1)[] setExtension(C1, C2)( immutable(C1)[] path, const(C2)[] ext ) if (isSomeChar!C1 && is(Unqual!C1 == Unqual!C2));
Examples
assert (setExtension("file", "ext") == "file.ext"); assert (setExtension("file", ".ext") == "file.ext"); assert (setExtension("file.old", "") == "file"); assert (setExtension("file.old", "new") == "file.new"); assert (setExtension("file.old", ".new") == "file.new");
See Also
withExtension
which does not allocate and returns a lazy range.
Authors
Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu