// C++ 实现 std::vector<std::string> split(const std::string & _source, const std::string & _delims = "/t/n ") { std::vector<std::string> _ret; //templates::split<void>(result, _source, _delims); size_t start = _source.find_first_not_of(_delims); while (start != _source.npos) { size_t end = _source.find_first_of(_delims, start); if (end != _source.npos) _ret.push_back(_source.substr(start, end-start)); else { _ret.push_back(_source.substr(start)); break; } start = _source.find_first_not_of(_delims, end + 1); } return _ret; } // C实现 // In this program, a loop uses strtok_s // to print all the tokens (separated by commas // or blanks) in two strings at the same time. // #include <string.h> #include <stdio.h> char string1[] = "A string/tof ,,tokens/nand some more tokens"; char string2[] = "Another string/n/tparsed at the same time."; char seps[] = " ,/t/n"; char *token1 = NULL; char *token2 = NULL; char *next_token1 = NULL; char *next_token2 = NULL; int main( void ) { printf( "Tokens:/n" ); // Establish string and get the first token: token1 = strtok_s( string1, seps, &next_token1); token2 = strtok_s ( string2, seps, &next_token2); // While there are tokens in "string1" or "string2" while ((token1 != NULL) || (token2 != NULL)) { // Get next token: if (token1 != NULL) { printf( " %s/n", token1 ); token1 = strtok_s( NULL, seps, &next_token1); } if (token2 != NULL) { printf(" %s/n", token2 ); token2 = strtok_s (NULL, seps, &next_token2); } } } OutPut: Tokens: A Another string string of parsed tokens at and the some same more time. tokens