一、目录:
二、程序主要源代码:
// 字符串替换
void CSearchReplaceStrDlg::OnReplace()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_strFind.IsEmpty())
{
AfxMessageBox("查找的字符串为空!");//判断编辑框字符串是否为空
return;
}
int num;
num=m_strData.Replace(m_strFind,m_strReplace);//替换字符串
CString str;
str.Format("共完成了%d处替换",num);
AfxMessageBox(str);
UpdateData(false);
}
//字符串查找
void CSearchReplaceStrDlg::OnSearch()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_strFind.IsEmpty())//判断编辑框字符串是否为空
{
AfxMessageBox("查找的字符串为空!");
return;
}
int pos=0;//记录查找位置
CString strpos,temp;
strpos.Format("%s字符串在原字符串中的起始位置为:\n",m_strFind);
while((pos>=0)&&(pos<m_strData.GetLength()))
{
pos=m_strData.Find(m_strFind,pos);//查找字符串
if(pos>=0)
{
temp.Format("%d ",pos);
strpos+=temp;
pos+=m_strFind.GetLength();//跳出循环,累计已经查找得字符长度
CString pos_x;
pos_x.Format("%d",pos);
}
}
AfxMessageBox(strpos);
}
三、程序运行结果:
四、资源:
https://download.csdn.net/download/sunjikui1255326447/12263176