http://www.maibaola.com
luojiafeng1984
全部博文(97)
2011年(1)
2009年(1)
2008年(14)
2007年(37)
2006年(44)
15927052
liang_sh
11697054
macy212
qq221669
bobo0516
along819
hades201
zhongcao
分类: LINUX
2008-04-23 14:02:16
#ifdef WIN32 #include "stdafx.h" #endif #include <iostream> #include <vector> #include <string> using namespace std; class CPickupEmail { public: CPickupEmail(void) {} ~CPickupEmail(void) {} void PickupEmail(const char* szBuf, const char* szFlag) { m_strEMailList.clear(); char *pFlag = strstr(szBuf, szFlag); char *pStart = pFlag; while ( pFlag != NULL ) { char ch = *(--pFlag); while ( pFlag != NULL && ( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_' ) ) { ch = *(--pFlag); } char szEmail[128]; memset((void *)szEmail, 0, sizeof(szEmail)); int i = 0; ch = *(++pFlag); while ( true ) { if ( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_' || ch == '.' || ch == '@' ) { szEmail[i++] = ch; ch = *(++pFlag); } else if ( strstr(pFlag, szFlag) == pFlag ) { szEmail[i++] = '@'; pStart += strlen(szFlag); ch = *(++pStart); } else if ( strstr(pFlag, ".") == pFlag ) { szEmail[i++] = '.'; pFlag += 4; ch = *(++pFlag); } else break; } pFlag = strstr(pFlag, szFlag); pStart = pFlag; if ( !IsExists(szEmail) ) m_strEMailList.push_back(szEmail); } } friend ostream& operator<<(ostream &out, CPickupEmail& EMail) { for ( vector<string>::const_iterator it = EMail.m_strEMailList.begin(); it != EMail.m_strEMailList.end(); it++ ) { out << (*it) << endl; } return out; } private: bool IsExists(const char* szEMail) { for ( vector<string>::const_iterator it = m_strEMailList.begin(); it != m_strEMailList.end(); it++ ) { if ( (*it) == szEMail ) return true; } return false; } private: vector<string> m_strEMailList; }; int main(int argc, char* argv[]) { CPickupEmail test; char szBuf[] = "How to pick up E-mail address from a string?luojiafeng1984@sina.com "; test.PickupEmail(szBuf, "@"); cout << test; return 0; }
上一篇:VC遍历文件夹
下一篇:Develop a Client-Server program step by step
登录 注册