replace_all
string find와 replace를 조합하여 replace_all 기능을 구현한다. 역시 기록용으로 정리한다.
소스코드
#include <string>
string replace_all(string &_str, const string& _from, const string& _to) {
size_t start_pos = 0;
while( (start_pos = _str.find(_from, start_pos)) != std::string::npos ) {
_str.replace(start_pos, _from.length(), _to);
start_pos += _to.length();
}
return _str;
}
'IT > programming' 카테고리의 다른 글
[C/C++] GCC C언어 constructor/destructor, 생성자/소멸자 (1) | 2022.09.07 |
---|---|
[C/C++] C++ sqlite3 wrapper class (3) | 2022.03.23 |
[C/C++] C++ string ltrim, rtrim, trim (2) | 2022.03.23 |
[PHP] 변수명으로 함수 호출 / function_exists() (2) | 2022.03.04 |
[PHP] URI '/'(slash) 중복 처리 / preg_replace, 정규식 (1) | 2022.03.04 |
댓글