在文件中查找替换(c#代码)

在文件中查找替换(c#代码)

ID:10219492

大小:33.00 KB

页数:3页

时间:2018-06-12

在文件中查找替换(c#代码)_第1页
在文件中查找替换(c#代码)_第2页
在文件中查找替换(c#代码)_第3页
资源描述:

《在文件中查找替换(c#代码)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace_179{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}publicintstart;privatevoidbutto

2、n1_Click(objectsender,EventArgse){try{richTextBox1.LoadFile(textBox1.Text,RichTextBoxStreamType.RichText);}catch(Exceptione1){MessageBox.Show("文?件t名?错洙?误ó.","提?示?对?话°框ò");}richTextBox1.Focus();}privatevoidForm1_Load(objectsender,EventArgse){label1.Text="filename";button1.Text="

3、open";button2.Text="save";label2.Text="findtext";label3.Text="replace";button3.Text="findnext";button4.Text="replaceall";}privatevoidbutton2_Click(objectsender,EventArgse){if(richTextBox1.Modified){richTextBox1.SaveFile(textBox1.Text,RichTextBoxStreamType.RichText);//打洙?开a写′字?板?

4、文?件t//richTextBox1.SaveFile(textBox1.Text,RichTextBoxStreamType.PlainText);//打洙?开atxt文?本?文?档苔?richTextBox1.Modified=false;MessageBox.Show("已?经-保馈?存?");richTextBox1.Focus();}}privatevoidtextBox2_TextChanged(objectsender,EventArgse){start=0;}privatevoidbutton3_Click(objectsender,E

5、ventArgse){stringstr1;str1=textBox2.Text;start=richTextBox1.Find(str1,start,RichTextBoxFinds.MatchCase);if(start==-1){MessageBox.Show("已?经-到?结á尾2","查é找ò结á束?对?话°框ò");start=0;}elsestart=start+str1.Length;richTextBox1.Focus();}privatevoidbutton4_Click(objectsender,EventArgse){strin

6、gstr1,str2;str1=textBox2.Text;str2=textBox3.Text;start=richTextBox1.Find(str1,start,RichTextBoxFinds.MatchCase);while(start!=-1){richTextBox1.SelectedText=str2;start=start+str2.Length;start=richTextBox1.Find(str1,start,RichTextBoxFinds.MatchCase);}MessageBox.Show("已?全?部?替?换?","查

7、é找ò结á束?对?话°框ò");start=0;richTextBox1.Focus();}/*privatevoidopenFileDialog1_FileOk(objectsender,CancelEventArgse){OpenFileDialogofd=newOpenFileDialog();ofd.InitialDirectory="d:\";ofd.Filter="*.rtf";}*/}}

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。