std::string 字符串替换


std::string 没有原生的字符串替换函数,需要自己来完成

 

 1 string& replace_str(string& str, const string& to_replaced, const string& newchars)     
 2 {
 3     for(string::size_type pos(0); pos != string::npos; pos += newchars.length())   
 4     {
 5         pos = str.find(to_replaced,pos);
 6         if(pos!=string::npos)     
 7            str.replace(pos,to_replaced.length(),newchars);     
 8         else  
 9             break;  
10     }     
11     return   str;     
12 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM