int index=str.Find(); CString str1=str.Mid(n,n);主要的函数
#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 ); } } OutputA string of ,,tokens and some more tokensTokens: A string of tokens and some more tokens strtok可以自己指定分隔符(不管是,空格或其他),代码也比较简洁,具体可以参考MSDN上的说明
char ch = " "; 里面有个空格 int index; index = str.Find(ch,0); CString findStr = str.Mid(0,index); findStr 就得到了你要的第一个字符串 ,其后面的类似。
CString str1=str.Mid(n,n);主要的函数
#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 );
}
}
OutputA string of ,,tokens
and some more tokensTokens:
A
string
of
tokens
and
some
more
tokens
strtok可以自己指定分隔符(不管是,空格或其他),代码也比较简洁,具体可以参考MSDN上的说明
int index;
index = str.Find(ch,0);
CString findStr = str.Mid(0,index);
findStr 就得到了你要的第一个字符串 ,其后面的类似。
char szch[5][10];
sscanf(str,"%s %s %s %s %s",szch,szch+1,szch+2,szch+3,szch+4);
符合你的要求吗?
如果不明白
请给我发短消息
请附: 帖子的地址
或根据http://www.vcshare.net上的联系方式与我联系
CString str1,str2;
str2 = str;
while(1)
{
if(str2.Find(" ") == -1)
{
str1 = str2;
break;
}
str1 = str2.Mid(0,str2.Find(" "));
str2 = str2.Mid(str2.Find(" ")+1);
}
str1依次取出字符串
{
arr.RemoveAll();
if (split == "")
{
arr.Add(str);
return;
} int pos = 0;
while(true)
{
if ((pos = str.Find(split)) != -1)
{
CString tmp = str.Left(pos);
str = str.Right(str.GetLength()-(pos+split.GetLength()));
arr.Add(tmp);
}
else
{
arr.Add(str);
break;
}
}
return;
}调用方法
CString str="aa ssss aaa dsl def"
CStringArray arr;
SplitString(str, " ", arr); //第二个参数表示用空格分隔
结果就在arr里面了
int curPos= 0;
resToken= str.Tokenize(_T(" "),curPos);
while (resToken != _T(""))
{
//你的操作
resToken= str.Tokenize(_T("%"),curPos);
}