比如将存储在数据库里面的一串用"/"隔开的数字组成字符串,提取出数字一次存入数组中。字符串如326.2/323.2/323.6/319.6/324.4/324.6/,提取出来为326.2,323.2,323.6,319.6,324.4,324.6存入数组中

解决方案 »

  1.   

    Info就是那个"326.2/323.2/323.6/319.6/324.4/324.6"的串
    char *ThisToken = strtok(Info,"/");
    for (;ThisToken != NULL;)
     {
        float TheNumber = atof(ThisToken); // TheNumber就是你需要的
        ThisToken = strtok(NULL,"/");
     }
      

  2.   


    1、放到 CString
    2、用 Find 也不难
      

  3.   

    char string[] = "326.2/323.2/323.6/319.6/324.4/324.6/";
    char seps[]   = "/";
    char *token;  token = strtok( string, seps );
       while( token != NULL )
         token = strtok( NULL, seps );
      

  4.   

    c函数strtok或MFC函数AfxExtractSubString,具体参见MSDN。
      

  5.   

    我现在试了一下你的代码,自己在前面加了一个数组char[6]用于显示分割后的字符串,然后把原来的
    while( token != NULL ) 
        token = strtok( NULL, seps ); 
    改成了
    while( token != NULL ) 
    {
    for (int i=0; i<6; i++)
    {
    token = strtok(NULL, seps ); 
    strcpy(num, token);
    }
    }
    结果有问题主要出在
    strcpy(num, token);
    现在不知道如何解决
      

  6.   

    问题在大家帮助下,我终于解决,可以顺利存入自己要的数组里面,代码如下
    char* token; 
    char pBuffer[100000];
    // CString str1="326.2/323.2/323.6/319.6/324.4/324.6/324.6/321.6/320.6/327.6/";
    strcpy(pBuffer,str);
    // token=&num;
    token = strtok(pBuffer,"/");  
    double a[10000]={0};
    // double *p=spliter(pBuffer);
    int i=0;
    while (token != NULL){ 
    // AfxMessageBox(token);
    //You Can Add token to your Array ^_^ 
    a[i]=atof(token);
    i++;
    token = strtok(NULL,"/");
    }