//std::string中替换子字符串的函数

#include <string>

void string_replace( std::string &strBig, const std::string &strsrc, const std::string &strdst )
{
 std::string::size_type pos = 0;
 std::string::size_type srclen = strsrc.size();
 std::string::size_type dstlen = strdst.size();
 
 while( (pos=strBig.find(strsrc, pos)) != std::string::npos )
 {
  strBig.replace( pos, srclen, strdst );
  pos += dstlen;
 }

posted on 2008-01-23 19:50  zdleek  阅读(9)  评论(0)    收藏  举报  来源