vc怎么截取字符串中的一部分,内容描述更清楚,大侠请看
vc如何截取字符串中的一部分,内容描述更清楚,大侠请看
比如我的一个CString date,date为2009-07-02,那么我要截取02,该怎么做呢?请高手帮忙看看。
------解决方案--------------------
CString::Tokenize
------解决方案--------------------
来自MSDN的例子:
/* STRTOK.C: In this program, a loop uses strtok
* to print all the tokens (separated by commas
* or blanks) in the string named "string".
*/
#include <string.h>
#include <stdio.h>
char string[] = "A string\tof ,,tokens\nand some more tokens";
char seps[] = " ,\t\n";
char *token;
void main( void )
{
printf( "%s\n\nTokens:\n", string );
/* Establish string and get the first token: */
token = strtok( string, seps );
while( token != NULL )
{
/* While there are tokens in "string" */
printf( " %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
}
}
输出内容:
A string of ,,tokens
and some more tokens
Tokens:
A
string
of
tokens
and
some
more
tokens
------解决方案--------------------
CString k=date.Mid(8,2);
比如我的一个CString date,date为2009-07-02,那么我要截取02,该怎么做呢?请高手帮忙看看。
------解决方案--------------------
CString::Tokenize
------解决方案--------------------
来自MSDN的例子:
/* STRTOK.C: In this program, a loop uses strtok
* to print all the tokens (separated by commas
* or blanks) in the string named "string".
*/
#include <string.h>
#include <stdio.h>
char string[] = "A string\tof ,,tokens\nand some more tokens";
char seps[] = " ,\t\n";
char *token;
void main( void )
{
printf( "%s\n\nTokens:\n", string );
/* Establish string and get the first token: */
token = strtok( string, seps );
while( token != NULL )
{
/* While there are tokens in "string" */
printf( " %s\n", token );
/* Get next token: */
token = strtok( NULL, seps );
}
}
输出内容:
A string of ,,tokens
and some more tokens
Tokens:
A
string
of
tokens
and
some
more
tokens
------解决方案--------------------
CString k=date.Mid(8,2);