Form1.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/*
* .NET FRAMEWORK 3.5版本
* 计算字符串长度
* 计算字符串中字符数,汉字两个字符
*
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;
using System.Windows.Forms;
namespace WindowsfORcOUNT
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string text = richTextBox1.Text.Trim().ToString();
label1.Text = "字符串长度\r\n共" + text.Length.ToString() + "字符";
label2.Text = "字符串中字符数\r\n共" + charNr(text).ToString() + "字符";//包含字符串中的汉字
label3.Text = "一个汉字两个字符" + charAscii(text).ToString();
}
/// <summary>
/// 一个汉字两个字符
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
private int charNr(string s)
{
int nCount = 0;
for (int i = 0; i < s.Length; i++)
{
//匹配汉字
Regex rx = new Regex(@"^[\u4e00-\u9fa5]{0,}$");
if (rx.IsMatch(s[i].ToString()))
{
nCount += 2; //汉字
}
else
{
nCount += 1;
}
}
return nCount;
}
/// <summary>
/// 把字符串转换为ASCII编码计算长度
/// </summary>
后面还有 18 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。