The OpenD Programming Language

withExtension

Replace existing extension on filespec with new one.

  1. auto withExtension(R path, C[] ext)
  2. auto withExtension(C1[] path, C2[] ext)
    withExtension
    (
    C1
    C2
    )
    (
    C1[] path
    ,
    C2[] ext
    )

Parameters

path C1[]

string or random access range representing a filespec

ext C2[]

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