字符串中如何以空格或回车换行分割一个CString字符串为多个字符串?


作者: Piccolo Goo  来源: 博客园  发布时间:2005-11-07 17:18  阅读:2476 次   原文链接   [收藏]  
 char *token;
CString bb="APEC 2001\n     Shang Hai china";
CString str[10];
char seps[] = " \n";
int count = bb.GetLength();

token = strtok(bb.GetBuffer(count), seps);

str[0].Format("%s", token);
TRACE("%s", str[0]);
int i = 1;
while(1)
{
token = strtok(NULL, seps);
if(token == NULL)
break;
str[i].Format("%s", token);
TRACE("%s\n", str[i]);
i++;
}

CString bb="APEC 2001\n Shang Hai china";
CString strTemp;
int nPosS,nPosR;
bb.TrimLeft();
bb.TrimLeft('\n');
bb.TrimRight();
bb.TrimRight('\n");
while( !bb.IsEmpty() )
{
    nPosS = bb.Find(' ');
    nPosR = bb.Find('\n');
    if( nPosS == 0 && nPosR ==0 )//只乘下一个了
    {
        strTemp = bb;
        break;
    }
    strTemp = bb.Left(min(nPosS,nPosR));//得到一个
    bb = bb.Right( bb.GetLength() - min(nPosS,nPosR) - 1 );
    bb.TrimLeft();
    bb.TrimLeft('\n');
    bb.TrimRight();
    bb.TrimRight('\n");
}

你可能感兴趣的:(null,token)