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);
}

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值