How to find and replace all occurrences of a substring in a string?

前端 未结 7 1425
无人共我
无人共我 2020-12-31 06:49

I need to search a string and edit the formatting of it.

So far I can replace the first occurrence of the string, but I am unable to do so with the next occurrences

相关标签:
7条回答
  • 2020-12-31 07:25

    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();
    }
    
    0 讨论(0)
提交回复
热议问题