cstring转为int字符串中如何以空格或回车换⾏分割⼀个CString字符串为多个
字符串?
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");
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。