且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何查找和替换字符串中所有出现的子字符串?

更新时间:2022-11-14 08:44:12

>

try the following

const std::string s = "*A";
const std::string t = "*A\n";

std::string::size_type n = 0;
while ( ( n = chartDataString.find( s, n ) ) != std::string::npos )
{
    chartDataString.replace( n, s.size(), t );
    n += t.size();
}