RT
我把文本文件读到CString里面 然后解析他们例如:cstring str= 半径,45,R,钢筋直径,90.8,D  ;
      
      
     应该有函数可以按逗号把cstring剪切吧?实际的str很长,应该写成循环才行...    多谢高手指点
     
     

解决方案 »

  1.   

    如何剪切cstring啊取完第一个逗号前的值,然后把它剪切掉...这样每次就只用取第一个逗号前面的值了望高手详解 最好写个代码我看看哦
      

  2.   

    cstring str= 半径,45,R,钢筋直径,90.8,D  ;
    int iLoop=0;
    iLoop=str.Find(_T(","),1);
    半径=str.Left(iLoop);
    str=str.Right(str.GetLength()-iLoop-1);
    iLoop=str.Find(_T(","),1);
    45=str.Left(iLoop);
    str=str.Right(str.GetLength()-iLoop-1);
    iLoop=str.Find(_T(","),1);
    R=str.Left(iLoop);
    str=str.Right(str.GetLength()-iLoop-1);
    iLoop=str.Find(_T(","),1);
    钢筋直径=str.Left(iLoop);
    str=str.Right(str.GetLength()-iLoop-1);
    iLoop=str.Find(_T(","),1);
    90.8=str.Left(iLoop);
    D=str.Right(str.GetLength()-iLoop-1);
    这样就分离了逗号中的字符
      

  3.   

    CString类的Find,Left,Right,Mid之类的函数可以做到
      

  4.   

    cstring str= 半径,45,R,钢筋直径,90.8,D  ; 
    int iLoop=0; 
    iLoop=str.Find(_T(","),1); 
    半径=str.Left(iLoop); 
    str=str.Right(str.GetLength()-iLoop-1); 
    iLoop=str.Find(_T(","),1); 
    45=str.Left(iLoop); 
    str=str.Right(str.GetLength()-iLoop-1); 
    iLoop=str.Find(_T(","),1); 
    R=str.Left(iLoop); 
    str=str.Right(str.GetLength()-iLoop-1); 
    iLoop=str.Find(_T(","),1); 
    钢筋直径=str.Left(iLoop); 
    str=str.Right(str.GetLength()-iLoop-1); 
    iLoop=str.Find(_T(","),1); 
    90.8=str.Left(iLoop); 
    D=str.Right(str.GetLength()-iLoop-1); 
    这样就分离了逗号中的字符 
      

  5.   

    CString str= L"半径,45,R,钢筋直径,90.8,D";str.Append(L",");//在末尾追加一个逗号方便下面处理int iStart = 0;
    CString strSingleOne;
    for( ;; )
    {
    const int iComma = str.Find( _T(','), iStart );if( iComma == -1 )
    break;strSingleOne= str.Mid( iStart, iComma - iStart );
    //strSingleOne:  得到一个由逗号分离的字符串,保存或者做相应处理。iStart = iComma + 1;
    }
      

  6.   

    CString s = "asd,fwef,cvdf,jyuj,3424,22d,fee";
    char* token = _tcstok( s.GetBuffer(0), "," );  
    while( token != NULL ) 

    MessageBox(token); 
    token = _tcstok( NULL, "," );
    }
      

  7.   

    CString.find(",");一个个截取出来
      

  8.   

    CString s = "asd,fwef,cvdf,jyuj,3424,22d,fee"; 
    char* token = _tcstok( s.GetBuffer(0), "," );  
    while( token != NULL ) 

    MessageBox(token); 
    token = _tcstok( NULL, "," );