MFC Edit多行获取每行和截取整数

截取行:

int i, nLineCount = m_myEdit.GetLineCount();//m_myEdit是与edit控件关联的变量

CString strText, strLine;
// Dump every line of text of the edit control.
for (i=0; i < nLineCount; i++)
{
   // length of line i:
   int len = m_myEdit.LineLength(m_myEdit.LineIndex(i));
   m_myEdit.GetLine(i, strText.GetBuffer(len), len);
   strText.ReleaseBuffer(len);
   strLine.Format(_T("line %d: '%s'\n"), i, strText);
   AFXDUMP(strLine);//输出得到的每行数据
}

 

 

 

截取整数:

CString str = "1234 654 882 哈哈 abc";
CString strBuffer[30];

AfxExtractSubString(strBuffer[0], str, 0, ' ');
for (int i=1; !strBuffer[i-1].IsEmpty(); i++)
{
AfxExtractSubString(strBuffer[i], str, i, ' ');
}

 

 

 

自己写过的一个:

int nLineCount=m_MyEdit.GetLineCount();
 for(int i=0;i<nLineCount;i++)
 {
  int len=m_MyEdit.LineLength(m_MyEdit.LineIndex(i));
  m_MyEdit.GetLine(i,strText.GetBuffer(len),len);
  strText.ReleaseBuffer(len);
  AfxExtractSubString(strBuffer[0], strText, 0, ' '); 

  dp.p[i][0]=_ttoi(strBuffer[0]);
  for(int j=1;!strBuffer[j-1].IsEmpty();j++)
  {
   AfxExtractSubString(strBuffer[j], strText, j, ' ');
   
   dp.p[i][j]=_ttoi(strBuffer[j]);
   //AfxMessageBox(strBuffer[j]);
  }  
 }

猜你喜欢

转载自blog.csdn.net/walker_m/article/details/80157911
MFC