replace_all这样常用的操作在C++却没直接提供,只好自己写个备忘。// replace all occurance of t in s to w void replace_all(std::string & s, std::string const & t, std::string const & w) { unsigned int pos = s.find(t), t_size = t.size(), r_size = w.size(); while(pos != std::string::npos){ // found s.replace(pos, t_size, w); pos = s.find(t, pos + r_size ); } }
C++,替换字符串的全部目标子串
最新推荐文章于 2024-06-07 20:28:43 发布