Replace part of a string with another string

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

    With C++11 you can use std::regex like so:

    #include 
    ...
    std::string string("hello $name");
    string = std::regex_replace(string, std::regex("\\$name"), "Somename");
    

    The double backslash is required for escaping an escape character.

提交回复
热议问题