第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在標(biāo)準(zhǔn)字符串中搜索/查找和替換?

如何在標(biāo)準(zhǔn)字符串中搜索/查找和替換?

C++
守候你守候我 2019-12-12 14:09:58
有沒有辦法用另一個字符串替換所有出現(xiàn)的子字符串std::string?例如:void SomeFunction(std::string& str){   str = str.replace("hello", "world"); //< I'm looking for something nice like this}
查看完整描述

3 回答

?
嚕嚕噠

TA貢獻(xiàn)1784條經(jīng)驗 獲得超7個贊

為什么不實施自己的替換?


void myReplace(std::string& str,

               const std::string& oldStr,

               const std::string& newStr)

{

  std::string::size_type pos = 0u;

  while((pos = str.find(oldStr, pos)) != std::string::npos){

     str.replace(pos, oldStr.length(), newStr);

     pos += newStr.length();

  }

}



查看完整回答
反對 回復(fù) 2019-12-13
?
波斯汪

TA貢獻(xiàn)1811條經(jīng)驗 獲得超4個贊

#include <boost/algorithm/string.hpp> // include Boost, a C++ library

...

std::string target("Would you like a foo of chocolate. Two foos of chocolate?");

boost::replace_all(target, "foo", "bar");

這是關(guān)于replace_all 的官方文檔。


查看完整回答
反對 回復(fù) 2019-12-13
  • 3 回答
  • 0 關(guān)注
  • 347 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號