Function BasicString.replace
Replaces the portion of the string that begins at character pos
and spans len
characters (or the part of the string in the slice slice
) by new contents.
ref typeof(this) replace
(
const size_t pos,
const size_t len,
scope const BasicString . CharType[] val,
const size_t count = 1
);
ref typeof(this) replace(Val)
(
const size_t pos,
const size_t len,
auto scope const ref Val val,
const size_t count = 1
)
if (isBasicString!Val || isSomeChar!Val || isSomeString!Val || isIntegral!Val || isCharArray!Val);
ref typeof(this) replace
(
scope const BasicString . CharType[] slice,
scope const BasicString . CharType[] val,
const size_t count = 1
);
ref typeof(this) replace(Val)
(
scope const BasicString . CharType[] slice,
auto scope const ref Val val,
const size_t count = 1
)
if (isBasicString!Val || isSomeChar!Val || isSomeString!Val || isIntegral!Val || isCharArray!Val);
Parameters
pos
position of the first character to be replaced.
len
number of characters to replace (if the string is shorter, as many characters as possible are replaced).
slice
sub-slice to be removed, slice
must be subset of this
val
inserted value.
Examples
{
BasicString!char str = "123456";
str .replace(2, 2, 'x', 5);
assert(str == "12xxxxx56");
}
{
BasicString!char str = "123456";
str .replace(2, 2, "abcdef");
assert(str == "12abcdef56");
}
{
BasicString!char str = "123456";
BasicString!char str2 = "xy";
str .replace(2, 3, str2);
assert(str == "12xy56");
}
{
BasicString!char str = "123456";
str .replace(str[2 .. 4], 'x', 5);
assert(str == "12xxxxx56");
}
{
BasicString!char str = "123456";
str .replace(str[2 .. 4], "abcdef");
assert(str == "12abcdef56");
}
{
BasicString!char str = "123456";
BasicString!char str2 = "xy";
str .replace(str[2 .. $], str2);
assert(str == "12xy56");
}