View source code
Display the source code in std/path.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.path.withExtension
Replace existing extension on filespec with new one.
auto withExtension(R, C)
(
R path,
C[] ext
)
if (isRandomAccessRange!R && hasSlicing!R && hasLength!R && isSomeChar!(ElementType!R) && !isSomeString!R && isSomeChar!C);
auto withExtension(C1, C2)
(
C1[] path,
C2[] ext
)
if (isSomeChar!C1 && isSomeChar!C2);
Parameters
Name | Description |
---|---|
path | string or random access range representing a filespec |
ext | the new extension |
Returns
Range with path
's extension (if any) replaced with ext
.
The element encoding type of the returned range will be the same as path
's.
See Also
Example
import std .array;
writeln(withExtension("file", "ext") .array); // "file.ext"
writeln(withExtension("file"w, ".ext"w) .array); // "file.ext"
writeln(withExtension("file.ext"w, ".") .array); // "file."
import std .utf : byChar, byWchar;
writeln(withExtension("file" .byChar, "ext") .array); // "file.ext"
writeln(withExtension("file"w .byWchar, ".ext"w) .array); // "file.ext"w
writeln(withExtension("file.ext"w .byWchar, ".") .array); // "file."w
Authors
Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.