C#中文本框内容的查找替换功能

来源:百度知道 编辑:UC知道 时间:2024/06/22 09:48:23
3个文本框 一个按钮
TextBox1是输入要查找的内容
TextBox2是输入要替换的内容
TextBox3是可以自己输入的文本

问题:能够分别实现查找和替换功能

求高手帮忙给个代码

按钮的单击事件中:

TextBox3.Text = TextBox3.Text.Replace(TextBox1.Text,TextBox2.Text);

就可以把替换结果显示在TextBox3中了

不可能给你整个源码了
思路是这样的
定义两个字符串
然后把2中内容给了1

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication15
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

//private void btnFind_Click(object sender, EventArgs e)
//{
// int i = textBox3.Text.IndexOf(textBox1.Text);
// if (i == -1)
// MessageBox.Show("不存在");
// else
// MessageBox.Show("在第" + i.ToString() + "位");
//}

private void btnChange_Click(object sender, EventArgs e)
{
textBox3.Text= textBox3.Text.Replace(textBox1.Text, textBox2.Text)