什么是Unicode letter

本文通过两段示例代码深入探讨了Unicode中字符的分类问题,特别是`Char.IsLetter`方法的实现原理及其判断标准,解释了为何一些特殊字符也会被认定为字母。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

起因:从一段代码说起

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            string temp = "1610MM001A衫片";
            foreach (Char item in temp)
            {
                if (char.IsLetter(item))
                {
                    Console.WriteLine(item);
                }
            }
            Console.ReadKey();
            
        }
    }
}

这段代码的输出  

原本以为是“MMA”,为什么汉子“衫片”也是?

F12,看一下

那么什么是Unicode(参见http://www.cnblogs.com/John-Marnoon/p/5825906.html),

那么,Unicode Letter都包括什么呢?

首先,查一下微软的Char.IsLetter 方法 (String, Int32)

https://msdn.microsoft.com/zh-cn/library/zff1at55(v=vs.110).aspx

其次,看一下IsLetter的源代码

 

进一步看看CheckLetter方法

 

 

大写字母、小写字母、标题字母(首字母大写)、修饰语字母、其他字母。

因为各个国家的语言都不一样,例如有的语言是带声调的。所以仅从个人理解以及涉及到的应用范围,这个unicode letter应该是所有汉字+英文字母,数字和符号大多不包括在内。

但是也有例外。。。。

 例如下面就会让你蒙圈了。。。 哈哈哈

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            bool a1 = char.IsLetter('!');
            bool a2 = char.IsLetter('ǃ');
            bool b1 = char.IsLetter('|');
            bool b2 = char.IsLetter('ǀ');

            Console.WriteLine(a1);
            Console.WriteLine(a2);
            Console.WriteLine(b1);
            Console.WriteLine(b2);
          Console.ReadKey();
        }
    }
}

如有错误,还请不吝指教。

附录

这五类具体包括什么,请查询 http://www.fileformat.info/info/unicode/category/index.htm

 

转载于:https://www.cnblogs.com/John-Marnoon/p/6046775.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值