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;
using System.Text.RegularExpressions;
namespace Example44
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int P_scalar = 0; //定义值类型变量 并 赋值为零
Regex P_regex = new Regex("^[\u4E00-\u9FA5]{0,}$"); // 创建正则表达式对象 用于判断字符 是否汉字!
// 上面这一串 是什么东西啊 ./....不懂
for (int i = 0; i < textBox1.Text.Length; i++) //遍历字符串
{
//如果 检测出来是 汉字 则计数器 + 1
P_scalar = P_regex.IsMatch(textBox1.Text[i].ToString()) ? ++P_scalar : P_scalar;
}
textBox2.Text = P_scalar.ToString();
}
}
}