新聞中心
C++編程語(yǔ)言應(yīng)方式靈活,一個(gè)功能的實(shí)現(xiàn)可以采用多種方式來(lái)實(shí)現(xiàn)。比如對(duì)于字符串替換就可以有很多方法來(lái)實(shí)現(xiàn),這里主要說(shuō)一下STL里的WString中的替換,雖然WString自帶了一個(gè)Replace函數(shù),但是只能替換一次,太不好了,因此單獨(dú)寫(xiě)了個(gè)C++字符串替換函數(shù)

創(chuàng)新互聯(lián)專注于惠州網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供惠州營(yíng)銷型網(wǎng)站建設(shè),惠州網(wǎng)站制作、惠州網(wǎng)頁(yè)設(shè)計(jì)、惠州網(wǎng)站官網(wǎng)定制、小程序開(kāi)發(fā)服務(wù),打造惠州網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供惠州網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。
C++字符串替換函數(shù)代碼如下:
- @brief 實(shí)現(xiàn)字符串替換
- @param orignStr 源串
- @param oldStr 查找的串
- @param newStr 替換的新串
- @return 返回修改后的串
- static wstring Replace(const wstring& orignStr,
const wstring& oldStr, const wstring& newStr);
[C++字符串替換函數(shù)的實(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;
- }
以上就是我們對(duì)C++字符串替換函數(shù)的相關(guān)介紹。
網(wǎng)站標(biāo)題:C++字符串替換函數(shù)具體實(shí)現(xiàn)方法詳解
URL地址:http://www.dlmjj.cn/article/dhhghip.html


咨詢
建站咨詢
