3

我说的 CString 类型是微软的.

我尝试了两种方法;

方法 1) 使用 msdn 网站上的 Remove() 和 Replace() 函数,Visual c++ 说Error:argument of type "const char*" is incompatible with argument of type "wchar_t"

具体我的代码是:

#include <cstring>

CString sTmp= sBody.Mid(nOffset);
CString sFooter= L"https://" + sTmp.Mid(0, nEnd );
sFooter.Remove("amp;");

而且我不想一次删除一个字符,因为它会摆脱其他'a'。

出于某种原因,当我将 sFooter 转换为 std::string 时,随机的“amp;”出现在不应该存在的字符串中......

我正在将 sFooter 转换为 std::string ,如下所示:

CT2CA p (sFooter);
string str (p);

方法2)将CString转换为std::string,然后使用erase()和remove()去掉“amp;”

#include <string>
#include <algorithm>

sFooter2.erase(std::remove(sFooter2.begin(), sFooter2.end(), "amp;"), sFooter2.end());

但 Visual Studio 的输出显示: http: //pastebin.com/s6tXQ48N

4

2 回答 2

5

尝试使用替换。

sFooter.Replace(_T("&amp;"), _T(""));

于 2012-08-01T03:38:02.413 回答
0

错误信息非常清楚。您需要使用宽字符串,而不是使用常规字符串。

sFooter.Remove(L"amp;");

同样根据文档,该Remove方法仅接受单个字符。您需要找到另一种方法来删除整个子字符串。

于 2012-08-01T02:27:26.260 回答