从QString转换为wstring,添加额外的转义序列

时间:2019-04-16 10:09:52

标签: c++ qt qstring wstring

我有一个类似

的QString。
QString qReplaceByText("**\\g<char>**");

如果我尝试将其转换为wstring,则将\替换为\\

std::wstring wReplaceByText = qReplaceByText.toStdWString();

qReplaceByText变为

**\\\\g<char>**

如何避免这种情况?

这是我的代码段

           std::wstring searchText(L"(?P<char>.)(?P=char)");;
            wsregex regExp;
            std::wstring strOut;
            try
            {
                regExp = wsregex::compile( searchText, boost::xpressive::icase );

                std::wstring wsObjectName =  L"tweet" ;

                std::wstring wReplaceByText = qReplaceByText.toStdWString();

                strOut.resize( wsObjectName.length() + wReplaceByText.length() );
                std::wstring::iterator itOut = strOut.begin();
                boost::xpressive::regex_replace(itOut, wsObjectName.begin() , wsObjectName.end(), regExp, wReplaceByText,  regex_constants::format_perl );
            }

0 个答案:

没有答案