Espaces de noms
Variantes
Affichages
Actions

cpp/string/basic string/replace : Différence entre versions

De cppreference.com
< cpp‎ | string‎ | basic string
m (1 version : Translate from the English version)
m (Use {{lc}}. Update links. Various fixes.)
 
(Une révision intermédiaire par un utilisateur est masquée)
Ligne 2 : Ligne 2 :
 
{{cpp/string/basic_string/title|replace}}
 
{{cpp/string/basic_string/title|replace}}
 
{{cpp/string/basic_string/navbar}}
 
{{cpp/string/basic_string/navbar}}
{{ddcl list begin}}
+
{{begin}}
{{ddcl list item | num=1 |
+
{{| num=1 |
 
basic_string& replace( size_type pos, size_type count,
 
basic_string& replace( size_type pos, size_type count,
 
                       const basic_string& str );
 
                       const basic_string& str );
Ligne 10 : Ligne 10 :
 
                       const basic_string& str );
 
                       const basic_string& str );
 
}}
 
}}
{{ddcl list item | num=2 |
+
{{| num=2 |
 
basic_string& replace( size_type pos, size_type count,
 
basic_string& replace( size_type pos, size_type count,
 
                       const basic_string& str,
 
                       const basic_string& str,
Ligne 19 : Ligne 19 :
 
                       InputIt first2, InputIt last2 );
 
                       InputIt first2, InputIt last2 );
 
}}
 
}}
{{ddcl list item | num=3 |
+
{{| num=3 |
 
basic_string& replace( size_type pos, size_type count,
 
basic_string& replace( size_type pos, size_type count,
 
                       const CharT* cstr, size_type count2 );
 
                       const CharT* cstr, size_type count2 );
Ligne 26 : Ligne 26 :
 
                       const CharT* cstr, size_type count2 );
 
                       const CharT* cstr, size_type count2 );
 
}}
 
}}
{{ddcl list item | num=4 |
+
{{| num=4 |
 
basic_string& replace( size_type pos, size_type count,
 
basic_string& replace( size_type pos, size_type count,
 
                       const CharT* cstr );
 
                       const CharT* cstr );
Ligne 33 : Ligne 33 :
 
                       const CharT* cstr );
 
                       const CharT* cstr );
 
}}
 
}}
{{ddcl list item | num=5 |
+
{{| num=5 |
 
basic_string& replace( size_type pos, size_type count,
 
basic_string& replace( size_type pos, size_type count,
 
                       size_type count2, CharT ch );
 
                       size_type count2, CharT ch );
Ligne 40 : Ligne 40 :
 
                       size_type count2, CharT ch );
 
                       size_type count2, CharT ch );
 
}}
 
}}
{{ddcl list item | num=6 | notes={{mark since c++11}} |
+
{{| num=6 | sincec++11 |
 
basic_string& replace( const_iterator first, const_iterator last,  
 
basic_string& replace( const_iterator first, const_iterator last,  
 
                       std::initializer_list<CharT> ilist );
 
                       std::initializer_list<CharT> ilist );
 
}}
 
}}
{{ddcl list end}}
+
{{end}}
  
 
{{tr|Remplace la partie de la chaîne signalée par le {{tt|[pos, pos + count)}} ou {{tt|[first, last)}} par une nouvelle chaîne .|Replaces the part of the string indicated by either {{tt|[pos, pos + count)}} or {{tt|[first, last)}} with a new string.}}
 
{{tr|Remplace la partie de la chaîne signalée par le {{tt|[pos, pos + count)}} ou {{tt|[first, last)}} par une nouvelle chaîne .|Replaces the part of the string indicated by either {{tt|[pos, pos + count)}} or {{tt|[first, last)}} with a new string.}}
Ligne 63 : Ligne 63 :
  
 
===Paramètres===
 
===Paramètres===
{{param list begin}}
+
{{begin}}
{{param list item | pos |{{tr| le début de la sous-chaîne qui va être remplacé| start of the substring that is going to be replaced}}}}
+
{{| pos |{{tr| le début de la sous-chaîne qui va être remplacé| start of the substring that is going to be replaced}}}}
{{param list item | count |{{tr| longueur de la chaîne qui va être remplacé| length of the substring that is going to be replaced}}}}
+
{{| count |{{tr| longueur de la chaîne qui va être remplacé| length of the substring that is going to be replaced}}}}
{{param list item | first, last |{{tr| plage de caractères qui va être remplacé| range of characters that is going to be replaced}}}}
+
{{| first, last |{{tr| plage de caractères qui va être remplacé| range of characters that is going to be replaced}}}}
{{param list item | str |{{tr| chaîne à utiliser pour le remplacement| string to use for replacement}}}}
+
{{| str |{{tr| chaîne à utiliser pour le remplacement| string to use for replacement}}}}
{{param list item | pos2 |{{tr| début de la chaîne à remplacer| start of the substring to replace with}}}}
+
{{| pos2 |{{tr| début de la chaîne à remplacer| start of the substring to replace with}}}}
{{param list item | count2 |{{tr| nombre de caractères de remplacement| number of characters to replace with}}}}
+
{{| count2 |{{tr| nombre de caractères de remplacement| number of characters to replace with}}}}
{{param list item | cstr |{{tr| pointeur vers la chaîne de caractères à utiliser pour le remplacement| pointer to the character string to use for replacement}}}}
+
{{| cstr |{{tr| pointeur vers la chaîne de caractères à utiliser pour le remplacement| pointer to the character string to use for replacement}}}}
{{param list item | ch |{{tr| caractère de la valeur à utiliser pour le remplacement| character value to use for replacement}}}}
+
{{| ch |{{tr| caractère de la valeur à utiliser pour le remplacement| character value to use for replacement}}}}
{{param list item | first2, last2 |{{tr| plage de caractères à utiliser pour le remplacement| range of characters to use for replacement}}}}
+
{{| first2, last2 |{{tr| plage de caractères à utiliser pour le remplacement| range of characters to use for replacement}}}}
{{param list item | init |{{tr| liste d'initialisation avec les caractères à utiliser pour le remplacement| initializer list with the characters to use for replacement}}}}
+
{{| init |{{tr| liste d'initialisation avec les caractères à utiliser pour le remplacement| initializer list with the characters to use for replacement}}}}
{{param list hreq}}
+
{{hreq}}
{{param list req concept | InputIt | InputIterator}}
+
{{req concept | InputIt | InputIterator}}
{{param list end}}
+
{{end}}
  
 
===Retourne la valeur===
 
===Retourne la valeur===
Ligne 82 : Ligne 82 :
  
 
===Exceptions===
 
===Exceptions===
{{c|std::out_of_range}} if {{tt|pos > length()}} or {{tt|pos2 > str.length()}}
+
{{|std::out_of_range}} if {{tt|pos > length()}} or {{tt|pos2 > str.length()}}
  
{{tr|{{c|std::length_error}} si la chaîne résultante ne dépasse pas la longueur maximale possible de chaîne ({{tt|{{c|std::string::npos}} - 1}})|{{c|std::length_error}} if the resulting string will exceed maximum possible string length ({{tt|{{c|std::string::npos}} - 1}})}}
+
{{tr|{{|std::length_error}} si la chaîne résultante ne dépasse pas la longueur maximale possible de chaîne ({{tt|{{|std::string::npos}} - 1}})|{{|std::length_error}} if the resulting string will exceed maximum possible string length ({{tt|{{|std::string::npos}} - 1}})}}
  
 
===Exemple===
 
===Exemple===
Ligne 106 : Ligne 106 :
 
}}
 
}}
  
 +
 +
 +
 +
 
[[ja:cpp/string/basic string/replace]]
 
[[ja:cpp/string/basic string/replace]]
 
[[pt:cpp/string/basic string/replace]]
 
[[pt:cpp/string/basic string/replace]]
 
[[ru:cpp/string/basic string/replace]]
 
[[ru:cpp/string/basic string/replace]]
 +

Version actuelle en date du 2 juillet 2013 à 05:47

 
 
Bibliothèque de chaînes de caractères
Chaînes à zéro terminal
Original:
Null-terminated strings
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Les chaînes d'octets
Chaines multi-octets
Les chaînes étendues
Classes
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string
char_traits
 
std::basic_string
Les fonctions membres
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::basic_string
basic_string::operator=
basic_string::assign
basic_string::get_allocator
Elément d'accès
Original:
Element access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::at
basic_string::operator[]
basic_string::front (C++11)
basic_string::back (C++11)
basic_string::data
basic_string::c_str
Les itérateurs
Original:
Iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::begin
basic_string::cbegin

(C++11)
basic_string::end
basic_string::cend

(C++11)
basic_string::rbegin
basic_string::crbegin

(C++11)
basic_string::rend
basic_string::crend

(C++11)
Capacité
Original:
Capacity
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::empty
basic_string::size
basic_string::length
basic_string::max_size
basic_string::reserve
basic_string::capacity
basic_string::shrink_to_fit (C++11)
Opérations
Original:
Operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::clear
basic_string::insert
basic_string::erase
basic_string::push_back
basic_string::pop_back (C++11)
basic_string::append
basic_string::operator+=
basic_string::compare
basic_string::replace
basic_string::substr
basic_string::copy
basic_string::resize
basic_string::swap
Recherche
Original:
Search
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::find
basic_string::rfind
basic_string::find_first_of
basic_string::find_first_not_of
basic_string::find_last_of
basic_string::find_last_not_of
Constantes
Original:
Constants
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::npos
Tiers fonctions
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
operator+
operator==
operator!=
operator<
operator>
operator<=
operator>=
swap(std::basic_string)
operator<<
operator>>
getline
stoi
stol
stoll
(C++11)
(C++11)
(C++11)
stoul
stoull
(C++11)
(C++11)
stof
stod
stold
(C++11)
(C++11)
(C++11)
to_string (C++11)
to_wstring (C++11)
Classes d'aide
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
hash<std::string>
hash<std::wstring>
hash<std::u32string>
hash<std::u16string>
(C++11)
 
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) (depuis C++11)
Remplace la partie de la chaîne signalée par le [pos, pos + count) ou [first, last) par une nouvelle chaîne .
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.
La nouvelle chaîne peuvent être:
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.
1)
str chaîne
Original:
string str
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
[pos2, pos2 + count2) chaîne de caractères ou str dans le [first2, last2) gamme
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.
3)
charcters count2 premiers de la chaîne de caractères pointée par cstr
Original:
first count2 charcters of the character string pointed to by cstr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4)
chaîne de caractères terminée par NULL pointé par cstr
Original:
null-terminated character string pointed to by cstr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
5)
count2 copies de ch caractère
Original:
count2 copies of character ch
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
6)
caractères dans la liste d'initialisation ilist
Original:
characters in the initializer list ilist
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Sommaire

[modifier] Paramètres

pos -
le début de la sous-chaîne qui va être remplacé
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 -
longueur de la chaîne qui va être remplacé
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 -
plage de caractères qui va être remplacé
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 -
chaîne à utiliser pour le remplacement
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 -
début de la chaîne à remplacer
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 -
nombre de caractères de remplacement
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 -
pointeur vers la chaîne de caractères à utiliser pour le remplacement
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 -
caractère de la valeur à utiliser pour le remplacement
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 -
plage de caractères à utiliser pour le remplacement
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 -
liste d'initialisation avec les caractères à utiliser pour le remplacement
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.

[modifier] Retourne la valeur

*this

[modifier] Exceptions

std::out_of_range if pos > length() or pos2 > str.length()

std::length_error si la chaîne résultante ne dépasse pas la longueur maximale possible de chaîne (std::string::npos - 1)
Original:
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.

[modifier] Exemple

#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';
}

Résultat :

A quick red fox jumps over the lazy dog.