Off topic to the question that you posed:

It looks like you are:

1) taking a std::string and converting it to a CString
2) trimming the CString
3) converting back to a std::string

Why not...