Replace part of a string with another string

前端 未结 15 2331
终归单人心
终归单人心 2020-11-22 02:54

Is it possible in C++ to replace part of a string with another string?

Basically, I would like to do this:

QString string(\"hello $name\");
string.re         


        
15条回答
  •  孤街浪徒
    2020-11-22 03:25

    wstring myString = L"Hello $$ this is an example. By $$.";
    wstring search = L"$$";
    wstring replace = L"Tom";
    for (int i = myString.find(search); i >= 0; i = myString.find(search))
        myString.replace(i, search.size(), replace);
    

提交回复
热议问题