问题描述:
帮我注释一下每行代码,就是解释下每行的意思,谢谢了
using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace Text
{
public partial class Form1 : Form
{
private static readonly Regex _cRegex = new Regex("[\u4e00-\u9fa5]");
public Form1()
{
InitializeComponent();
Tb.TextChanged += Tb_TextChanged;
}
void Tb_TextChanged(object sender, EventArgs e)
{
var cCounter = 0;
foreach (var c in Tb.Text)
{
if (!isChineseChar(c)) continue;
cCounter++;
}
TbChineseCounter.Text = cCounter.ToString("n0");
TbTotalCounter.Text = Tb.Text.Length.ToString("n0");
}
static bool isChineseChar(char ch)
{
return _cRegex.IsMatch(ch.ToString(CultureInfo.InvariantCulture));
}
}
}
using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace Text
{
public partial class Form1 : Form
{
private static readonly Regex _cRegex = new Regex("[\u4e00-\u9fa5]");
public Form1()
{
InitializeComponent();
Tb.TextChanged += Tb_TextChanged;
}
void Tb_TextChanged(object sender, EventArgs e)
{
var cCounter = 0;
foreach (var c in Tb.Text)
{
if (!isChineseChar(c)) continue;
cCounter++;
}
TbChineseCounter.Text = cCounter.ToString("n0");
TbTotalCounter.Text = Tb.Text.Length.ToString("n0");
}
static bool isChineseChar(char ch)
{
return _cRegex.IsMatch(ch.ToString(CultureInfo.InvariantCulture));
}
}
}
问题解答:
我来补答展开全文阅读