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.

  1. typeof(this) replace(size_t pos, size_t len, CharType[] val, size_t count)
  2. typeof(this) replace(size_t pos, size_t len, Val val, size_t count)
  3. typeof(this) replace(CharType[] slice, CharType[] val, size_t count)
    struct BasicString
    ref return
    typeof(this)
    replace
    (
    scope const CharType[] slice
    ,
    scope const CharType[] val
    ,
    const size_t count = 1
    )
  4. typeof(this) replace(CharType[] slice, Val val, size_t count)

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");
}

Meta