Replace a substring of this string.

Synopsis

Declared in <bslstl_string.h>

basic_string&
replace(
    size_type outPosition,
    size_type outNumChars,
    basic_string const& replacement,
    size_type position,
    size_type numChars = npos);

Description

Replace the specified outNumChars characters starting at the specified outPosition in this string (or the suffix of this string starting at outPosition if outPosition + outNumChars > length()) with the optionally specified numChars characters starting at the specified position in the specified replacement string (or the suffix of replacement starting at position if `position + numChars > replacement.length()). If `numChars is not specified, npos` is used. Return a reference providing modifiable access to this string. Throw `out_of_range if outPosition > length() or `position > replacement.length()`.

Return Value

reference providing modifiable access to this string

Parameters

Name

Description

outPosition

index at which replacement begins

outNumChars

number of characters to replace

replacement

replacement character sequence

position

starting index

numChars

number of characters

Created with MrDocs