如何提取CString类型字符串中的字符?
例如:
CString str="2.3 65 7.8 15";
  (顺便说句,用myFile.ReadString(str)方法读取的就是这种类型吧)
字符串的数字都用空格隔开的
那么我怎样才可以取出一个个的数据2.3  65   7.8 和15呢?
谢谢!

解决方案 »

  1.   

    先用str.GetBuffer.获得字符串的存储位置。
    然后,利用string.h里的函数,处理得到各个单词。
      

  2.   

    CString s;
    while(str.Find(' ') != -1)
    {
         s = Left(str.Find(' '));
         str.Delete(0, str.Find(' ')+1);
    }
      

  3.   

    用C函数库的strtokExample
    /* STRTOK.C: In this program, a loop uses strtok
     * to print all the tokens (separated by commas
     * or blanks) in the string named "string".
     */#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 );
       }
    }Output
    A string   of ,,tokens
    and some  more tokensTokens:
     A
     string
     of
     tokens
     and
     some
     more
     tokens