C++ 过滤特殊字符

 template class CExcludeCharacter { public: typedef _T* Iter; CExcludeCharacter(const _T* ptr,int num, _T sentinel) { m_iNum = num; m_sentinel = sentinel; m_pSpecialCharacters = ptr; } ~CExcludeCharacter() { m_pSpecialCharacters = NULL; } BOOL operator()(_T ch) { BOOL bExisted = FALSE; const _T* pch = NULL; pch = find(m_pSpecialCharacters,m_pSpecialCharacters + m_iNum -1,ch); if (*pch != m_sentinel) { bExisted = TRUE; } return bExisted; } private: _T m_sentinel; int m_iNum; const _T* m_pSpecialCharacters; }; #include #include using namespace std; void test() { char szSpecialCharacter[] = {'//','/',':','*','?','/"','<','>','|','0'}; char szSource[MAX_PATH]; memset(szSource,0x00,sizeof(szSource)); sprintf_s(szSource,MAX_PATH,"This a sa//mple ab/out h>ow to delete a gro*up of spec:ial chara?cters fro|m a give/n stri(szSpecialCharacter, sizeof(szSpecialCharacter)/sizeof(char),szSpecialCharacter[9])); while (iterCharacter != vSource.end()) { vSource.erase(iterCharacter); iterCharacter = find_if(vSource.begin(),vSource.end(),CExcludeCharacter(szSpecialCharacter, sizeof(szSpecialCharacter)/sizeof(char),szSpecialCharacter[9])); } }

 

你可能感兴趣的:(algorithm)