![]() |
VOOZH | about |
The std::string::replace() function in C++ is used to replace characters or substrings inside a string. It is a member function of the std::string class and provides multiple overloads for replacing text using indexes or iterators.
Hello C++
Explanation:
| Syntax | Description |
|---|---|
| str.replace(pos, count, n, ch) | Replaces count characters starting from pos with n copies of character ch. |
| str.replace(pos, count, str2) | Replaces characters with another string. |
| str.replace(pos1, count, str2, pos2, len) | Replaces characters with a substring of another string. |
| str.replace(first, last, n, ch) | Replaces iterator range with repeated characters. |
| str.replace(first, last, str2) | Replaces iterator range with another string. |
| str.replace(first, last, str2_first, str2_last) | Replaces iterator range with another iterator range. |
n index-based replacement, positions are specified using integer indexes.
The string::replace() method can be used to replace the multiple characters with single repeated character.
Syntax
str1.replace(pos, n, m, c)
Parameters
Return Value: It returns the original string after replacing the multiple characters with single repeated character.
!!! World
Syntax
str1.replace(pos, n, str2)
Parameters
Return Value: It returns the original string after replacing the multiple characters by another string.
Hello World
The string::replace() method can also be used to replace the multiple characters with a part of the given string.
Syntax
str1.replace(pos1, n, str2, pos2,m)
Parameters
Return Value: It returns the original string after replacing the multiple characters by another substring.
Hello World
The string::replace() method can be used to replace the multiple characters with a single repeated character.
Syntax
str1.replace(first, last, n, c);
Parameters
Return Value: It return the original string after replacing the multiple characters with single repeated character.
!!! World
The string::replace() method can also be used to replace the multiple characters with a string.
Syntax
str1.replace(first, last, str2)
Parameters
Return Value: It return the original string after replacing the multiple characters by another string.
Hello World
The string::replace() method can also be used to replace the multiple characters with a substring.
Syntax
str1.replace(first, last, str2_first, str2_last)
Parameters
Return Value: It returns the original string after replacing the multiple characters by another substring.
Hello World