string 의 문자열 치환 replace 구현
등록자 : cpueblo (유광희), 2008-12-24
string 의 문자열 치환 replace 구현
std string 의 문자열 치환 함수 입니다.
string __fastcall str_replace(const string &str, const string &pattern, const string &replace)
{
string result = str;
string::size_type pos = 0;
string::size_type offset = 0;
while((pos = result.find(pattern, offset)) != string::npos)
{
result.replace(result.begin() + pos, result.begin() + pos + pattern.size(), replace);
offset = pos + replace.size();
}
return result;
}
사용 예제
string newurl = str_replace (url, "\\", "/");
http://codesarang.com. mail to cpueblo cpueblo.com
|