3

The CString type I am talking about is microsoft's.

I've attempted two methods;

Method 1) using the Remove() and Replace() function found on msdn website, and Visual c++ says Error:argument of type "const char*" is incompatible with argument of type "wchar_t"

Specifically my code is:

#include <cstring>

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

And I don't want to remove a single character at a time because it will get rid of other 'a's.

For some reason, when I convert sFooter to a std::string, random "amp;"s appear in the string that shouldn't be there...

I am converting sFooter to a std::string like this:

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

Method 2) Converting the CString to std::string, then using erase() and remove() to get rid of the "amp;"s

#include <string>
#include <algorithm>

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

But Visual studio's output shows this: http://pastebin.com/s6tXQ48N

minusatwelfth
  • 191
  • 6
  • 14

2 Answers2

5

Try using Replace.

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

Joseph Willcoxson
  • 5,853
  • 1
  • 15
  • 29
1

The error message is pretty clear. Instead of using regular strings you need to use wide strings.

sFooter.Remove(L"amp;");

Also according to the documentation the Remove method only accepts a single character. You'll need to find another way to remove an entire substring.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • When I try that, there's a red line under L, saying `Error:argument of type "const wchar_t*" is incompatible with argument of type "wchar_t"` – minusatwelfth Aug 01 '12 at 02:42