How to find and replace string?

后端 未结 10 1104
感动是毒
感动是毒 2020-11-27 03:51

If s is a std::string, then is there a function like the following?

s.replace(\"text to replace\", \"new text\");
10条回答
  •  清酒与你
    2020-11-27 04:02

    // replaced text will be in buffer.
    void Replace(char* buffer, const char* source, const char* oldStr,  const char* newStr)
    {
        if(buffer==NULL || source == NULL || oldStr == NULL || newStr == NULL) return; 
    
        int slen = strlen(source);
        int olen = strlen(oldStr);
        int nlen = strlen(newStr);
    
        if(olen>slen) return;
        int ix=0;
    
        for(int i=0;i

提交回复
热议问题