سؤال

Good day. I am currently doing a Server-Client Chat Program using sockets in MFC C++ (in Visual Studio 2010). This is my first C++ program as we were never taught of the said language way back in college (shame)

Anyways, so far I've been doing good. Then, I have added string length which would count how many characters were sent. Thankfully, because of searching the internet and forums, I've made it work. Then here's my problem, the code counts the white spaces and I don't need that. I read about .Trim() but its not what I need. I also did try .Replace() but it's not working. Any other ideas? Here's my code.

//string length //m_Msg is my message

CString strCount;
strCount = m_Msg;

//strCount = strCount.Replace(" " , ""); int Count = strCount.GetLength();

Thanks, thanks for any ideas that may help.

هل كانت مفيدة؟

المحلول

You can use int CString::Remove( TCHAR ch ) It takes the character you want to remove as argument and returns the number of characters removed.

strCount.Remove(' ');

Should do what you want. I also agree with the comment saying you should use std::string instead.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top