std::string 찾은 문자열을 특정 문자열로 대체
View 15,696 | 작성일2010.11.17 20:38
관련링크
본문
문자열을 대체하는 방법 ㅋ
#include <iostream>
using namespace std;
void ReplaceAll (string& strSrc, const string& strFind, const string& strDest)
{
size_t j;
while ((j = strSrc.find(strFind)) != string::npos)
strSrc.replace(j, strFind.length(), strDest);
}
int main (int argc, char** argv)
{
string strSrc = "this is test and this is are";
string strFind = "this";
string strReplace = "that";
cout << "Before :" << strSrc.c_str() << endl;
ReplaceAll ( strSrc, strFind, strReplace );
cout << "After :" << strSrc.c_str() << endl;
return 0;
}