2.VC(custom)-两种解析EDIT控件上文本的方式

http://hgy413.com/1269.html

研究了那么久,在EDIT控件上解析一行一行文本的方式整理了一下:

设EDIT控件关联的变量为m_WriteEdit ,单行的解析方法

first:

int nLen=m_WriteEdit.GetLineCount();
 
int nStart=0;
 for (int i=0;i<nLen;i+=1)
 {
 
	CString  strBuf;
 
   CString szText;
  m_WriteEdit.GetWindowText(szText);
  int nEnd=0;
  nEnd=szText.Find(_T("/r/n"),nStart);
  if (nEnd!=-1)
  {
   strBuf=szText.Mid(nStart,nEnd-nStart);
   nStart=nEnd+2;
  }
  else
  {
 
   int a=szText.GetLength();
   strBuf=szText.Right(a-nStart);
  }
 
}

second:

第二种:

int nLen=m_WriteEdit.GetLineCount();
 
 
 for (int i=0;i<nLen;i+=1)
 {
 
	CString  strBuf;
  int nBeforeLen=m_WriteEdit.LineIndex(i);
  int nLineLength=m_WriteEdit.LineLength(nBeforeLen);
 
  strBuf=szText.Mid(nBeforeLen+i,nLineLength);//为什么+i,可以考虑下面例子
 
}

为什么+i,不明白可以参考MSDN小例子:

 

// The string for replacing.
CString strString(_T("Hi, we're the replacements."));
int nBegin, nEnd;
 
// Replace the second line, if it exists, of the edit control
// with the text strString.
if ((nBegin = m_myEdit.LineIndex(1)) != -1)
{
   nEnd = nBegin + m_myEdit.LineLength(nBegin);
   m_myEdit.SetSel(nBegin, nEnd);//nBegin=行数,nEnd=nBegin+行长,所以一行的范围是(行数(index),行数+行长
   m_myEdit.ReplaceSel(strString);
}

 

 

 

 

你可能感兴趣的:(2.VC(custom)-两种解析EDIT控件上文本的方式)