新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C++字符串替換函數(shù)具體實現(xiàn)方法詳解
C++編程語言應方式靈活,一個功能的實現(xiàn)可以采用多種方式來實現(xiàn)。比如對于字符串替換就可以有很多方法來實現(xiàn),這里主要說一下STL里的WString中的替換,雖然WString自帶了一個Replace函數(shù),但是只能替換一次,太不好了,因此單獨寫了個C++字符串替換函數(shù)

創(chuàng)新互聯(lián)專注于惠州網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供惠州營銷型網(wǎng)站建設,惠州網(wǎng)站制作、惠州網(wǎng)頁設計、惠州網(wǎng)站官網(wǎng)定制、小程序開發(fā)服務,打造惠州網(wǎng)絡公司原創(chuàng)品牌,更為您提供惠州網(wǎng)站排名全網(wǎng)營銷落地服務。
C++字符串替換函數(shù)代碼如下:
- @brief 實現(xiàn)字符串替換
- @param orignStr 源串
- @param oldStr 查找的串
- @param newStr 替換的新串
- @return 返回修改后的串
- static wstring Replace(const wstring& orignStr,
const wstring& oldStr, const wstring& newStr);
[C++字符串替換函數(shù)的實現(xiàn)]
- std::wstring Replace( const wstring& orignStr, const
wstring& oldStr, const wstring& newStr )- {
- size_t pos = 0;
- wstring tempStr = orignStr;
- wstring::size_type newStrnewStrLen = newStr.length();
- wstring::size_type oldStroldStrLen = oldStr.length();
- while(true)
- {
- pos = tempStr.find(oldStr, pos);
- if (pos == wstring::npos) break;
- tempStr.replace(pos, oldStrLen, newStr);
- pos += newStrLen;
- }
- return tempStr;
- }
以上就是我們對C++字符串替換函數(shù)的相關介紹。
名稱欄目:C++字符串替換函數(shù)具體實現(xiàn)方法詳解
網(wǎng)頁URL:http://m.5511xx.com/article/dhhghip.html


咨詢
建站咨詢
