不知道我能否表达清楚,我想将一组数据( 2, 4, 5, 6, 7, 8  这些数据每个后
面有一个逗号,而且逗号后有一空格,最后一个数据没有逗号)
放入一个edit控件中,然后点一个按纽,使得这些放如一个int数组中,我的
和edit控件和一个CString变量相连着,我其实就是想问问怎么使用CString
变量我不知道应该怎么做,最好能给代码示例,谢谢各位了

解决方案 »

  1.   

    下面是我原来做的一个咚咚
    主要是两个输入框,第一个框输入关键字(数字),第二个框输入对应字符串,然后根据关键字排序,关键字用空格隔开
    GetDlgItemText(IDC_KEY,orikey);
    GetDlgItemText(IDC_STR,oristr);
    CString temstr=orikey;//.Trim()
    CString temstr2=oristr;//.Trim()
    int i=0,thenum[20];
    CString theinfo[20];
    while(temstr.Find(" ")>=0){
    if(!oristr.IsEmpty()&&temstr2.Find(" ")<0)break;//.Trim()
    thenum[i]=atoi(temstr.Left(temstr.Find(" ")));
    temstr=temstr.Right(temstr.GetLength()-temstr.Find(" ")-1);
    if(!oristr.IsEmpty()){//.Trim()
        theinfo[i]=temstr2.Left(temstr2.Find(" "));
    temstr2=temstr2.Right(temstr2.GetLength()-temstr2.Find(" ")-1);
    }
    ++i;
    }
    //heap::bheap[i]=int(temstr);
    if(temstr.Find(" ")>0){
    thenum[i]=atoi(temstr.Left(orikey.Find(" ")));
    }else
    thenum[i]=atoi(temstr);//.Trim()
    if(!oristr.IsEmpty())//.Trim()
    if(temstr2.Find(" ")>0)
    {
     theinfo[i]=temstr2.Left(oristr.Find(" "));
    }else //if(temstr.Find(" ")<=0)
    theinfo[i]=temstr2;
      

  2.   

    和edit控件相连的CString假定为:m_strInput点击按钮后:
    UpdateData();
    CString strInData = m_strInput;
    CDWordArray aInt;
    while(!strInData.IsEmpty())
    {
       int nPos = strInData.Find(_T(","),0);
       if(nPos == -1)
       {
          int nIn = atoi((LPCTSTR)strInData);
          aInt.Add(nIn);
          strInData.Empty();
          continue;
       }
       CString strNum = strInData.Left(nPos);
       strInData = strData.Right(strInData.GetLength() - nPos - 1);
       int nIn = atoi((LPCTSTR)strInData);
       aInt.Add(nIn);
    }
      

  3.   

    houwenqiang() 的方法不错,不过我提议先检测"("以之为开始