C++/문자열 교체 헬퍼 std:string Replace

  1. inline int Replace_Helper(string* source, const string& replaceString, const string& fmt)
  2. {
  3.     std::string::size_type offset = 0;
  4.     offset = source->find(replaceString, offset);
  5.     if (offset != std::string::npos)
  6.     {
  7.         source->replace(offset, replaceString.length(), fmt);    
  8.         return 1;
  9.     }
  10.     return 0;
  11. }
  12. int Replace(string* source, const string& replaceString, const string& fmt)
  13. {
  14.     int seq = 0;
  15.     while (Replace_Helper(source, replaceString, fmt)) ++seq;
  16.     return seq;
  17. }
  18. ...
  19. string fmt("");
  20. Replace(&str, "▶", fmt);

교묘했습니다 ▶ 인터뷰   신
↓
교묘했습니다  인터뷰   신

이 글에는 0 개의 댓글이 있습니다.