如何操作
如何找出textbook一中的数据所包含的字母和数字的个数,并将统计结果显示在textbook二和三中
如何找出textbook一中的数据所包含的字母和数字的个数,并将统计结果显示在textbook二和三中
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);
}
}
}