m0_74388520 2022-12-22 09:58 采纳率: 100%
浏览 18
已结题

textbook1和textbox 2和textbox3的交互如何完成

img

如何操作
如何找出textbook一中的数据所包含的字母和数字的个数,并将统计结果显示在textbook二和三中

  • 写回答

3条回答 默认 最新

  • CSDN专家-showbo 2022-12-22 10:07
    关注
    using System;
    using System.Windows.Forms;
    using System.IO;
    using System.Linq;
    using System.Text;
    namespace demo
    {
        public partial class Form1 : Form
        {
            string dataPath = @"f:\data.txt";
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                textBox1.Text = File.ReadAllText(dataPath, Encoding.UTF8);
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                var charcount = 0;
                var numbercount = 0;
                foreach (var c in textBox1.Text)
                {
                    if (c >= '0' && c <= '9') numbercount++;
                    if ((c >= 'A' && c <= 'Z' )|| (c >= 'a' && c <= 'z')) charcount++;
                }
                textBox2.Text = charcount.ToString();
                textBox3.Text = numbercount.ToString();
    
                File.AppendAllText(dataPath, $"\r\n字母个数:{charcount}\r\n数字个数:{numbercount}",Encoding.UTF8);
            }
        }
    
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 12月30日
  • 已采纳回答 12月22日
  • 创建了问题 12月22日