mfc 请大家一起帮下忙哈,字符串截取问题

2024-12-01 14:06:14
推荐回答(1个)
回答1:

CStringA str= "->中国->美国->英国->德国->";

CStringA resToken;
int curPos = 0;
//方法一,用Tokenize
resToken= str.Tokenize("->",curPos);
while (resToken != "")
{
printf("Resulting token: %s\n", resToken);
resToken = str.Tokenize("->", curPos);
};

//方法二,用Find和Mid
int n = str.Find( "->" );
while ( n != -1 )
{
resToken = str.Mid( n + 2, 4 );
if ( resToken == "") break;
printf("Resulting token: %s\n", resToken);
n = str.Find( "->", n+2 );
}