C#中Char.IsDigit()和Char.IsNumber()的区别 [英] Difference between Char.IsDigit() and Char.IsNumber() in C#

查看:29
本文介绍了C#中Char.IsDigit()和Char.IsNumber()的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#中Char.IsDigit()Char.IsNumber()有什么区别?

推荐答案

Char.IsDigit()Char.IsNumber() 的子集.

一些数字"但不是数字的字符包括 0x00b2 和 0x00b3,它们是上标 2 和 3(²"和³")以及作为分数的字形,例如¼"、½",和'¾'.

Some of the characters that are 'numeric' but not digits include 0x00b2 and 0x00b3 which are superscripted 2 and 3 ('²' and '³') and the glyphs that are fractions such as '¼', '½', and '¾'.

请注意,IsDigit() 返回true 的字符很多,因为它们不在 0x30 到 0x39 的 ASCII 范围内,例如这些泰语数字字符: '๐' '๑' '๒' '๓' '๔' '๕' '๖' '๗' '๘' '๙'.

Note that there are quite a few characters that IsDigit() returns true for that are not in the ASCII range of 0x30 to 0x39, such as these Thai digit characters: '๐' '๑' '๒' '๓' '๔' '๕' '๖' '๗' '๘' '๙'.

这段代码告诉您哪些代码点不同:

This snippet of code tells you which code points differ:

static private void test()
{
    for (int i = 0; i <= 0xffff; ++i)
    {
        char c = (char) i;

        if (Char.IsDigit( c) != Char.IsNumber( c)) {
            Console.WriteLine( "Char value {0:x} IsDigit() = {1}, IsNumber() = {2}", i, Char.IsDigit( c), Char.IsNumber( c));
        }
    }
}

这篇关于C#中Char.IsDigit()和Char.IsNumber()的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆