I read a blog in csdn: http://blog.csdn.net/shuice/article/details/5618058
Is a class for string splitting. However, the Code provided by the author cannot be compiled in vc6.0, and I am not very familiar with the definition of this type of template.
template<>class SplitAssist<char>{public:static long GetLength(const char* pszStr){return strlen(pszStr);}static const char* FindString(const char * pszSource, const char * pszFlags){return strstr(pszSource, pszFlags);}};
I don't know what the role of the template <char> is to provide parameters.
So I made some modifications to his code.
// File name splitstring. h // purpose: Split the string class // call example: // vector <string> vectstr1; // vector <cstring> vectstr2; // list <wstring> liststr3; // splitstring ("Hello World", "", vectstr1); // splitstring (_ T ("Hello World"), _ T (""), vectstr2 ); // splitstring (L ("Hello World"), L (""), liststr3); # ifndef _ split_string_h _ # DEFINE _ split_string_h _ # include <string. h> class splitassist {public: static long getlength (const char * pszs Tr) {return strlen (pszstr);} static long getlength (const wchar_t * pwszstr) {return wcslen (pwszstr);} static const char * findstring (const char * pszsource, const char * pszflags) {return strstr (pszsource, pszflags);} static const wchar_t * findstring (const wchar_t * pwszsource, const wchar_t * szflags) {return wcsstr (pwszsource, pwszflags) ;}}; template <class basetype, class stringcontenttype> void splitstrin G (const basetype * pszsource, const basetype * pszflags, stringcontenttype & strreturn) {strreturn. clear (); If (pszsource = NULL) | (pszflags = NULL) {return;} size_t isourcelen = splitassist: getlength (pszsource ); size_t iflaglen = splitassist: getlength (pszflags); If (iflaglen = 0) {stringcontenttype: value_type STR (pszsource, isourcelen); strreturn. push_back (STR); return;} const basetype * pposstart = Pszsource; For (const basetype * pposfind = splitassist: findstring (pposstart, pszflags); pposfind! = NULL; pposfind = splitassist: findstring (pposstart, pszflags) {int ilenvalid = pposfind-pposstart; If (ilenvalid> 0) {stringcontenttype: value_type STR (pposstart, ilenvalid); strreturn. push_back (STR);} pposstart = pposfind + iflaglen;} int ilenvalid = isourcelen-(pposstart-pszsource); If (ilenvalid> 0) {stringcontenttype: value_type STR (pposstart, ilenvalid); strreturn. push_back (STR) ;}# endif
Welcome to the discussion!