C#——创建窗体程序,过滤输入框中连续重复出现的字符

设计以下界面

编写代码

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace a

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            string zf = textBox1.Text;

            char newch, oldch;

            oldch = ' ';

            label2.Text = "过滤后的字符串";

            for (int i = 1; i < zf.Length; i++)

            {

                newch=(char)zf[i];

                if (oldch==newch) continue;

                label2.Text +=newch;

                oldch = newch;

            }

            label2.Text += "\n\n过滤前的字符串" + zf;

            textBox1.Text = "";

        }

       

    }

}

 

运行结果

猜你喜欢

转载自blog.csdn.net/lmm0513/article/details/88773349