std::string 찾은 문자열을 특정 문자열로 대체 > IT Note

본문 바로가기
사이트 내 전체검색

IT Note

std::string 찾은 문자열을 특정 문자열로 대체
0

View 15,004  | 작성일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;
}

댓글목록

등록된 댓글이 없습니다.

IT Tip&Tech 목록

게시물 검색

접속자집계

오늘
1,272
어제
901
최대
6,399
전체
661,631
Copyright © LittleCandle All rights reserved.
문의메일 : littlecandle99@gmail.com
모바일 버전으로 보기