withExtension

Replace existing extension on filespec with new one.

  1. auto withExtension(R path, C[] ext)
    withExtension
    (
    R
    C
    )
    (,
    C[] ext
    )
    if (
    isRandomAccessRange!R &&
    hasSlicing!R
    &&
    hasLength!R
    &&
    isSomeChar!(ElementType!R)
    &&
    &&
    )
  2. auto withExtension(C1[] path, C2[] ext)

Parameters

path R

string or random access range representing a filespec

ext C[]

the new extension

Return Value

Type: auto

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.

Examples

import std.array;
assert(withExtension("file", "ext").array == "file.ext");
assert(withExtension("file"w, ".ext"w).array == "file.ext");
assert(withExtension("file.ext"w, ".").array == "file.");

import std.utf : byChar, byWchar;
assert(withExtension("file".byChar, "ext").array == "file.ext");
assert(withExtension("file"w.byWchar, ".ext"w).array == "file.ext"w);
assert(withExtension("file.ext"w.byWchar, ".").array == "file."w);

See Also

Meta