Search code examples
c++xmlstringnewlinecstring

Getting rid of newline in CString in C++


I have a html/xml document that is originally a CString and I want to get rid of all the newlines, essentially put everything into one line. I've tried converting it to std::String and using:

#include <algorithm>
#include <string>

str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());

But it didn't work.


Solution

  • You need only to use the method remove

    CString str = _T("Test newline \nremove"), str2;
    str.Remove('\n');