Skip to content

Instantly share code, notes, and snippets.

@hxhb
Created January 7, 2019 03:26
Show Gist options
  • Save hxhb/7df084d11256af4d4fcff740b4a4826c to your computer and use it in GitHub Desktop.
Save hxhb/7df084d11256af4d4fcff740b4a4826c to your computer and use it in GitHub Desktop.
std::string replace_substring(const std::string& file,const std::string& replace_src,const std::string& replace_target)
{
std::string resault("");
std::string::size_type begin_index=0;
std::string::size_type pos_index=file.find(replace_src,begin_index);
while(pos_index != std::string::npos)
{
resault += std::string(file.begin()+begin_index,file.begin()+pos_index);
resault += replace_target;
begin_index = pos_index+replace_src.size();
pos_index = file.find(replace_src,begin_index);
}
resault += std::string(file,begin_index,file.size()-1);
return resault;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment