std::basic_string::replace
Aus cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody> basic_string& replace( size_type pos, size_type count, const basic_string& str ); basic_string& replace( const_iterator first, const_iterator last, const basic_string& str ); |
(1) | |
basic_string& replace( size_type pos, size_type count, const basic_string& str, size_type pos2, size_type count2 ); template< class InputIt > basic_string& replace( const_iterator first, const_iterator last, InputIt first2, InputIt last2 ); |
(2) | |
basic_string& replace( size_type pos, size_type count, const CharT* cstr, size_type count2 ); basic_string& replace( const_iterator first, const_iterator last, const CharT* cstr, size_type count2 ); |
(3) | |
basic_string& replace( size_type pos, size_type count, const CharT* cstr ); basic_string& replace( const_iterator first, const_iterator last, const CharT* cstr ); |
(4) | |
basic_string& replace( size_type pos, size_type count, size_type count2, CharT ch ); basic_string& replace( const_iterator first, const_iterator last, size_type count2, CharT ch ); |
(5) | |
basic_string& replace( const_iterator first, const_iterator last, std::initializer_list<CharT> ilist ); |
(6) | (seit C++11) |
Ersetzt den Teil des Strings entweder
[pos, pos + count) oder [first, last) mit einer neuen Zeichenfolge angegeben .Original:
Replaces the part of the string indicated by either
[pos, pos + count) or [first, last) with a new string.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Der neue String kann eine der folgenden sein:
Original:
The new string can be one of:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
1)
String
strOriginal:
string
strThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2)
substring
[pos2, pos2 + count2) der str oder Zeichen im Bereich [first2, last2)Original:
substring
[pos2, pos2 + count2) of str or characters in the range [first2, last2)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
3)
erste
count2 charcters der Zeichenfolge, auf die cstrOriginal:
first
count2 charcters of the character string pointed to by cstrThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
4)
null-terminierte Zeichenkette, auf die
cstrOriginal:
null-terminated character string pointed to by
cstrThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
5)
count2 Kopien Charakter chOriginal:
count2 copies of character chThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
6)
Zeichen in der Initialisierungsliste
ilistOriginal:
characters in the initializer list
ilistThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Parameter
| pos | - | Start der substring, werde ersetzt werden wird
Original: start of the substring that is going to be replaced The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| count | - | Länge der Teilzeichenfolge, werde ersetzt werden wird
Original: length of the substring that is going to be replaced The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| first, last | - | Reihe von Zeichen, die gehen ersetzt werden wird
Original: range of characters that is going to be replaced The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| str | - | String, der für Ersatz zu verwenden
Original: string to use for replacement The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| pos2 | - | Start der substring mit ersetzen
Original: start of the substring to replace with The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| count2 | - | Anzahl der Zeichen, mit ersetzen
Original: number of characters to replace with The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| cstr | - | Zeiger auf die Zeichenkette für Ersatz zu verwenden
Original: pointer to the character string to use for replacement The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| ch | - | Zeichenwert für Ersatz zu verwenden
Original: character value to use for replacement The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| first2, last2 | - | Bereich von Zeichen für den Austausch verwenden
Original: range of characters to use for replacement The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| init | - | initializer Liste mit den Zeichen für Ersatz zu verwenden
Original: initializer list with the characters to use for replacement The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| Type requirements | ||
-InputIt must meet the requirements of InputIterator.
| ||
Rückgabewert
*this
Ausnahmen
std::out_of_range if pos > length() or pos2 > str.length()
std::length_error wenn die resultierende String wird maximal mögliche String-Länge (
std::string::npos - 1) überschreitenOriginal:
std::length_error if the resulting string will exceed maximum possible string length (
std::string::npos - 1)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Beispiel
#include <iostream>
#include <string>
int main()
{
std::string str("The quick brown fox jumps over the lazy dog.");
str.replace(10, 5, "red"); // (4)
str.replace(str.begin(), str.begin() + 3, 1, 'A'); // (5)
std::cout << str << '\n';
}
Output:
A quick red fox jumps over the lazy dog.