MFC Cstring查找字符串中某个特定字符出现的次数

1、使用标准库函数count_if

2、此函数所需要的头文件

#include <algorithm>
#include <functional>

3、例子

例如有一个字符串

CString m_EditSendData;

m_EditSendData.Format(_T("%s"), _T("123 456 789") );

int nCount = std::count_if((LPCTSTR)m_EditSendData, (LPCTSTR)m_EditSendData + m_EditSendData.GetLength(),std::bind2nd(std::equal_to<char>(),' ' ));//计算空格数量

这样得到的结果nCount 就是字符串中所含有的空格字符的个数

原文地址:https://www.cnblogs.com/LYF-LIUDAO/p/9814413.html