Replace part of a string with another string

前端 未结 15 2581
终归单人心
终归单人心 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

    std::string has a replace method, is that what you are looking for?

    You could try:

    s.replace(s.find("$name"), sizeof("$name") - 1, "Somename");
    

    I haven't tried myself, just read the documentation on find() and replace().

提交回复
热议问题