[转载]CRichEditCtrl系列讲堂4自己遇到的查找问题及解决方案

呵呵,这是我自己的总结啊,不看是你的损失

我用字符串的形式对CRichEditCtrl进行查找:具体代码如下:

UpdateData(TRUE);
 CString str; 
 m_RichTex.GetWindowText(str);
 int len=strEdit.GetLength();
 long index=0,end_index=0;    
    repText.Format("%d",len);
 strEdit.MakeLower();
 str.MakeLower(); 

 if(m_down==IDC_DOWN)
  {
   m_RichTex.GetSel(index,end_index);//向下查找
   index=str.Find(strEdit,end_index);
   if (index!=-1)
   {
    m_RichTex.SetSel(index,index+len);
    m_RichTex.SetFocus();
   }
   else
   {
    index=str.Find(strEdit,0);
    if (index==-1)
    {
     MessageBox("搜索的字符串未找到", " 提示", MB_OK);
    }
    m_RichTex.SetSel(index,index+len);
    m_RichTex.SetFocus();

   }
  }
  else
  {
   m_RichTex.GetSel(index,end_index);//向上查找
   CString strReverse=str.MakeReverse();
   CString strEditReverse=strEdit.MakeReverse();
   index=strReverse.Find(strEditReverse,str.GetLength()-index);
  if (index!=-1)
  {
   end_index=str.GetLength()-index-1;
  }
  else
  {
   index=strReverse.Find(strEditReverse,0);
   if (index==-1)
   {
    MessageBox("搜索的字符串未找到", " 提示", MB_OK);
   }
   end_index=str.GetLength()-index-1;
  }
  m_RichTex.SetSel(end_index+1-len,end_index+1);
  m_RichTex.SetFocus();
  }
 } 

结果运行时查找结果和字符对应不上。经网上查资料得知将空间中的内容转化成字符串存在这编码的差异,还有可能和CRichEdit版本有关。综合各种原因我的解决办法就是回头去用Findtext.

相信会有很多和我一样的菜鸟会遇到相同问题,希望能给你带去光明。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值